Tag: C#的

在C#中检查Type实例是否为空值枚举

我如何检查types是否是C#中可为null的枚举类似 Type t = GetMyType(); bool isEnum = t.IsEnum; //Type member bool isNullableEnum = t.IsNullableEnum(); How to implement this extension method?

更容易的方式来填充整数在.NET中的列表

可能重复: 在.NET中填充整数列表 有没有更简单或更优雅的方式来初始化C#中的整数列表除此之外呢? List<int> numberList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 要么 for(int i = 1; i <= 10; i++) { numberList.Add(i); } 这似乎不太实际 – 特别是如果列表包含大量的值。 循环是一个更实际的解决scheme吗? 谢谢, CC

线程安全列表<T>属性

我想要List<T>一个实现作为一个属性,可以毫无疑问地使用线程安全。 像这样的东西: private List<T> _list; private List<T> MyT { get { // return a copy of _list; } set { _list = value; } } 似乎仍然需要返回一个集合的副本(克隆),所以如果我们迭代集合的地方,同时集合被设置,那么不会引发exception。 如何实现线程安全的集合属性?

WCF给出一个不安全的或不正确的安全故障错误

我正在尝试使用远程的svc web服务。 我使用svcutil.exe创build了代理类,之后我将这个类添加到我的控制台应用程序中,但是会产生一个错误: 从另一方收到一个不安全的错误或不正确的安全错误。 查看内部故障例外,了解故障代码和详细信息。 System.ServiceModel.FaultException:validation消息的安全性时发生错误 我没有创buildWCF端,这是一个远程的svc。 请帮忙。 <?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="EloquaDataTransferService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint […]

在function参数中“this”

看一些HtmlHelpers的代码示例,我看到如下所示的声明: public static string HelperName(this HtmlHelper htmlHelper, …more regular params ) 我不记得在哪里可以看到这种types的结构 – 有人可以解释“这个”的目的吗? 我认为通过声明一些公共静态的东西意味着这个类不需要被实例化 – 那么在这种情况下什么是“this”呢?

ASP.NET .NET MVC禁用每个字段级别的客户端validation

我正在使用ASP .NET MVC 3与数据注释和jQueryvalidation插件。 有没有办法标记一个特定的字段(或某些数据注释)只应该validation服务器端? 我有一个电话号码字段,上面有一个掩码插件,正则expression式validation器在用户端疯狂。 正则expression式只是一个自动保险箱(如果有人决定破解javascriptvalidation),所以我不需要它在客户端运行。 但我仍然喜欢其他validation运行客户端。

如何总结一个在C#中的整数数组

有没有更好的更短的方式比迭代数组? int[] arr = new int[] { 1, 2, 3 }; int sum = 0; for (int i = 0; i < arr.Length; i++) { sum += arr[i]; } 澄清: 更好的主要意味着更清洁的代码,但对性能改进的暗示也是受欢迎的 (就像已经提到的:分裂大数组)。 这不是我寻找杀手性能改进 – 我只是想知道,这种语法糖是不是已经可用:“有String.Join – 什么诠释int []?”。

如何用variables消息抛出std :: exceptions?

这是我经常做的一个例子,当我想添加一些信息到exception: std::stringstream errMsg; errMsg << "Could not load config file '" << configfile << "'"; throw std::exception(errMsg.str().c_str()); 有没有更好的方法来做到这一点?

asp.net MVC3 razor:根据用户angular色显示actionlink

我是MVC的新手。 我希望能够隐藏一些用户的一些actionlinks。 说我有一个“创build”行动链接,我只希望pipe理员看到并点击。 我想在asp.net中使用某种“loggedintemplate”,但它似乎不能在剃刀中工作。 我可以使用某种代码块来检查当前用户和她的angular色,但这可能不是最佳实践吗? 我的index.cshtml .. // want some adminauth attribute here… @Html.ActionLink("Create New", "Create") 我的控制器.. // GET: /Speaker/Create [Authorize(Roles = "Administrators")] public ActionResult Create() { return View(); }

如何在C#中通过指纹查找证书

我正在使用此代码通过其指纹find证书。 证书存在于个人证书库中的证书pipe理器中,但是此代码没有find该证书。 请告诉我我在哪里做错了。 namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string certThumbPrint = "‎‎fe14593dd66b2406c5269d742d04b6e1ab03adb1"; X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); // Try to open the store. certStore.Open(OpenFlags.ReadOnly); // Find the certificate that matches the thumbprint. X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint, false); certStore.Close(); // Check to see if our certificate was added […]