Tag: C#的

如何比较genericstypes的值?

如何比较genericstypes的值? 我已经减less到最小的样本: public class Foo<T> where T : IComparable { private T _minimumValue = default(T); public bool IsInRange(T value) { return (value >= _minimumValue); // <– Error here } } 错误是: 运算符'> ='不能应用于'T'和'T'types的操作数。 到底怎么回事!? T已经被限制为IComparable ,甚至当它限制为值types( where T: struct )时,我们仍然不能应用任何运算符< , > , <= , >= , ==或!= 。 (我知道涉及Equals()解决方法存在==和!= ,但对关系运算符没有帮助)。 所以,有两个问题: 我们为什么要观察这种奇怪的行为? 什么让我们不能比较已知是IComparable的genericstypes的值? 这难道不是以某种方式击败了通用约束的全部目的吗? […]

设置QLineEdit只接受数字

我有一个QLineEdit用户只能input数字。 那么QLineEdit有没有数字设置?

在cookie中存储密码是否安全?

我的Web应用程序的主页有一个RememberMecheckbox。 如果用户检查它,我将存储电子邮件ID和密码在Cookie中。 这是我的代码: if (this.ChkRememberme != null && this.ChkRememberme.Checked == true) { HttpCookie cookie = new HttpCookie(TxtUserName.Text, TxtPassword.Text); cookie.Expires.AddYears(1); Response.Cookies.Add(cookie); } 我想知道的是: 在cookie中存储密码是否安全? 什么是适当的方式做同样的事情? 为cookie设置时间的最佳做法是什么?

如何使用迭代器浏览vector? (C ++)

目标是访问stringvector的“nth”元素,而不是[]运算符或“at”方法。 据我所知,迭代器可以用来浏览容器,但我从来没有使用过迭代器,而我正在阅读的内容令人困惑。 如果有人可以给我一些关于如何实现这一目标的信息,我将不胜感激。 谢谢。

如何在C#中传递一个函数作为参数?

是否有可能在C#中传递一个函数作为参数? 我可以使用Func或Action类来完成,但这迫使我一次声明整个函数签名。 当我尝试使用委托,我得到一个编译错误,说它不能将方法组转换为委托。 我正在使用Axial ,我试图让用户调用Web服务。 我要去的是能够创buildVisual Studio代理类,然后传入生成的函数。 函数签名并不重要,因为生成的代码只使用函数名称。 然而,我想传递的function,而不是名称有两个原因:能够使用代理的URL属性和编译器错误,如果Web服务不存在或在Visual Studio中更新。 public void AlertIt(object o) { Axial.DOM.Window.Alert(o.ToString()); } public void CallAddService() { object[] param = new object[] { int.Parse(txtA.Text), int.Parse(txtB.Text) }; Axial.ServerScript.CallWebService(new WSProxy.WS().Add, param, AlertIt, AlertIt); } class Axial.ServerScript { public void CallWebService(Delegate method, object[] param, Action<object> successCallback, Action<object> failureCallback) { // translate to javascript (already […]

如何实现ASP.NET MVC的reCaptcha?

如何在ASP.NET MVC和C#中实现reCaptcha?

make:没有什么可以做的“全部”

我正在通过例如pgm来创build一个make文件。 http://mrbook.org/tutorials/make/ 我的文件夹eg_make_creation包含以下文件, desktop:~/eg_make_creation$ ls factorial.c functions.h hello hello.c main.c Makefile Makefile文件 # I am a comment, and I want to say that the variable CC will be # the compiler to use. CC=gcc # Hwy!, I am comment no.2. I want to say that CFLAGS will be the #options I'll pass to the compiler […]

尝试并行运行多个HTTP请求,但被Windows(registry)限制

我正在开发一个应用程序(winforms C#.NET 4.0),我通过一个简单的HTTP请求从第三方访问查找function。 我用一个参数调用一个url,并返回一个小string,查找的结果。 很简单。 然而挑战是我必须做很多这样的查找(几万),而且我想限制所需的时间。 所以我想平行运行请求(比如10-20)。 我使用一个ThreadPool来做到这一点,我的代码的短版本看起来像这样: public void startAsyncLookup(Action<LookupResult> returnLookupResult) { this.returnLookupResult = returnLookupResult; foreach (string number in numbersToLookup) { ThreadPool.QueueUserWorkItem(lookupNumber, number); } } public void lookupNumber(Object threadContext) { string numberToLookup = (string)threadContext; string url = @"http://some.url.com/?number=" + numberToLookup; WebClient webClient = new WebClient(); Stream responseData = webClient.OpenRead(url); LookupResult lookupResult = parseLookupResult(responseData); returnLookupResult(lookupResult); […]

在c#中IsNullOrEmpty和IsNullOrWhiteSpace的区别

这个命令在c#中有什么区别 string text= " "; 1-string.IsNullOrEmpty(text.Trim()) 2-string.IsNullOrWhiteSpace(text)

没有后台代码的ASP.net页面

我有一个C#代码后面的ASP.Net页面。 不过,我被要求不要使用代码,以便在SharePoint中部署更容易。 有没有一种方法可以在ASP.Net页面中包含C#代码,而不必在文件后面使用单独的代码?