Tag: C#的

如何从主AppDomain卸载程序集?

我想知道如何卸载加载到主AppDomain的程序集。 我有以下代码: var assembly = Assembly.LoadFrom( FilePathHere ); 当我完成时,我需要/希望能够卸载这个程序集。 谢谢你的帮助。

什么时候应该打开和closures连接到SQL Server

我有一个简单的静态类,其中有几个方法。 每个方法打开一个SqlConnection,查询数据库并closures连接。 这样,我确信我总是closures与数据库的连接,但另一方面,我不喜欢总是打开和closures连接。 下面是我的方法的例子。 public static void AddSomething(string something) { using (SqlConnection connection = new SqlConnection("…")) { connection.Open(); // … connection.Close(); } } 考虑到方法是在一个静态类,我应该有一个静态成员包含单个SqlConnection? 我应该如何以及何时放弃它? 什么是最佳实践?

传递整数作为常量引用与复制

这可能是一个愚蠢的问题,但我注意到,在大量的API中,很多方法签名采用整数参数,而不是被修改的: void method(int x); 而不是: void method(const int &x); 对我来说,看起来这两个function完全一样。 (编辑:显然不是在某些情况下,看到R塞缪尔Klatchko答案)在前者,价值被复制,因此不能改变原来的。 在后者中,通过了一个不变的引用,所以原文不能改变。 我想知道的是,为什么一个人会这么做,是因为他们的performance与前者基本相同甚至更好? 例如传递一个16位值或32位值而不是32位或64位地址? 这是我能想到的唯一合乎逻辑的原因,我只想知道这是否正确,如果不是这样,为什么以及何时您更喜欢int x不是const int &x和/或反之亦然。 谢谢。

不区分大小写的stringcomp in C

我有两个邮政编码char* ,我想比较,忽略大小写。 有这样的function吗? 或者我必须循环使用tolower函数,然后进行比较? 任何想法如何将这个函数与string中的数字反应 谢谢

自动映射器复制列表到列表

我有这些类: public class Person { public int Id{ get; set ;} public string FirstName{ get; set ;} public string LastName{ get; set ;} } public class PersonView { public int Id{ get; set ;} public string FirstName{ get; set ;} public string LastName{ get; set ;} } 我定义了这个: Mapper.CreateMap<Person, PersonView>(); Mapper.CreateMap<PersonView, Person>() .ForMember(person => person.Id, […]

你如何查询一个pthread,看看它是否仍在运行?

在我的析构函数中,我想干净地破坏一个线程。 我的目标是等待一个线程完成执行,然后破坏线程。 我发现查询pthread的唯一情况是pthread_attr_setdetachstate,但是这只能告诉你,如果你的线程是: PTHREAD_CREATE_DETACHED PTHREAD_CREATE_JOINABLE 这两者与线程是否仍在运行无关。 你如何查询一个pthread,看看它是否仍在运行?

如何在连接string中包含&符号?

我正在使用entity framework4为一个简单的应用程序,并希望将我的连接凭据烤到以下连接string: <connectionStrings> <add name="MyEntities" connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost\DEV;Initial Catalog=MyDB;UserId=myUser;Password=jack&jill;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> </connectionStrings> 但是,密码(我无法更改)包含&符号。 ASP.NET引发: Configuration Error: An error occurred while parsing EntityName. Line XX, position YYY. Configuration Error: An error occurred while parsing EntityName. Line XX, position YYY. 如果我用&amp; ,我得到一个SqlException: Login failed for user 'myUser'. 通常这个技巧是有效的,但是我猜测有些东西是失败的,因为这在技术上是连接string中的连接string。 我应该在这里做什么? 我的大部分课程包括如下代码: using (var context = new MyEntities()) […]

epoll边缘触发选项的目的是什么?

从epoll的手册页: epoll is a variant of poll(2) that can be used either as an edge-triggered or a level-triggered interface 什么时候使用边缘触发选项? 手册页给出了一个使用它的例子,但我不明白为什么在这个例子中是必要的。

std :: string是否包含空终止符?

下面的string是否包含空终止符'\ 0'? std::string temp = "hello whats up"; 谢谢! 🙂

ASP.NET Web API与ninject绑定

我刚刚安装了mvc4 rc更新,我试图build立一个运气好的API应用程序。 我正在使用ninject,但不能让我的控制器加载。 我不断收到错误 types“Api.Controllers.ConsumerController”没有默认的构造函数 我对mvc很陌生,使用注射剂,请耐心等待。 我没有做任何特别的事情,通过nuget创build的默认绑定 public static class NinjectWebCommon { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); /// <summary> /// Starts the application /// </summary> public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } /// <summary> /// Stops the application. /// </summary> public static void Stop() { bootstrapper.ShutDown(); } /// <summary> /// […]