草庐IT

c# - 抛出 'System.StackOverflowException' 类型的异常

我的程序抛出这个异常:System.StackOverflowException当编译器执行设置属性时。wine类:classwine{publicintyear;publicstringname;publicstaticintno=5;publicwine(intx,stringy){year=x;name=y;no++;}publicintprice{get{returnno*5;}set{price=value;}}}程序类:classProgram{staticvoidMain(string[]args){winew1=newwine(1820,"JackDaniels");C

c# - 等于 System.Collections.Generic.List<T>... 的方法?

我正在创建一个派生自List的类...publicclassMyList:List{}我已经覆盖了MyListItem的Equals...publicoverrideboolEquals(objectobj){MyListItemli=objasMyListItem;return(ID==li.ID);//IDisapropertyofMyListItem}我也想在MyList对象中有一个Equals方法,它将比较列表中的每个项目,在每个MyListItem对象上调用Equals()。简单地调用...会很好MyListl1=newMyList(){newMyListItem(1),ne

c# - 在 System.IO.Directory.GetFiles() 中排除文件扩展名

有没有办法获取文件夹中的文件数,但我想排除扩展名为jpg的文件?Directory.GetFiles("c:\\Temp\\").Count(); 最佳答案 试试这个:varcount=System.IO.Directory.GetFiles(@"c:\\Temp\\").Count(p=>Path.GetExtension(p)!=".jpg");祝你好运! 关于c#-在System.IO.Directory.GetFiles()中排除文件扩展名,我们在StackOverflow上找到

c# - "The type or namespace name ' 引用System.Xml.dll时XmlSerializer ' could not be found"错误

我已经在这上面浪费了几个小时:XmlSerializerserializer;是的,using在那里,引用在那里,我在VS2010中使用.NET4.0制作了整个解决方案,所以它不是那些东西。如果我进入对象资源管理器,我可以在正确的命名空间中找到我想要的XmlSerializer类,但是如果我尝试在我的代码文件中键入上面的行并进行编译,我会得到可怕的Thetypeornamespacename'XmlSerializer'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)死亡警告。我也没有在Intelli

c# - 缺少 System.Windows.Freezable

我有一个类库项目,我在其中为我的WPF应用程序和RIA服务保留了一些接口(interface)和类。进入我要添加成员的类(class)之一BrushBackgroundColor{set;get;}或SolidColorBrushBackgroundColor{set;get;}但是我得到了这个错误。Error2Thetype'System.Windows.Freezable'isdefinedinanassemblythatisnotreferenced.Youmustaddareferencetoassembly'WindowsBase,Version=4.0.0.0,Cultur

c# - 奇怪的系统.__佳能异常(exception)

我有一个使用单例类的Windows服务ThreadQueue.当服务启动时,它会调用ThreadQueue.Start()然后,此类接受任务并将其排队,将并发性限制为可配置的线程数。ThreadQueue.Start()在服务启动时被调用一次。有时,服务运行几个小时后,我会收到以下异常:Application:myservice.exeFrameworkVersion:v4.0.30319Description:Theprocesswasterminatedduetoanunhandledexception.ExceptionInfo:System.NullReferenceExcep

c# - 如何从虚拟键代码转换为 System.Windows.Forms.Keys

如果我使用win32调用拦截按键,我现在就有了一个键码。有没有办法将其转换为System.Windows.Forms.Keys值? 最佳答案 使用KeyInterop.KeyFromVirtualKey(). 关于c#-如何从虚拟键代码转换为System.Windows.Forms.Keys,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/554015/

C# - 用户设置损坏

我们在读取标准.Net用户设置时发生了一个罕见的异常(这是在VS2008的“项目属性”中找到的):System.Configuration.ConfigurationErrorsExceptionwascaughtMessage="Configurationsystemfailedtoinitialize"Source="System.Configuration"BareMessage="Configurationsystemfailedtoinitialize"Line=0StackTrace:atSystem.Configuration.ConfigurationManager.P

c# - 将 System.Decimal 转换为 System.Guid

我有一个很大的字典,其中的键是十进制,但是System.Decimal的GetHashCode()非常糟糕。为了证明我的猜测,我运行了一个包含100.000个相邻小数的for循环并检查了分布。100.000个不同的十进制数字仅使用2(两个!!!)不同的哈希码。十进制表示为16个字节。就像Guid一样!但是Guid的GetHashCode()分布非常好。如何尽可能便宜地将小数转换为C#中的Guid?不安全的代码是可以的!编辑:请求测试,所以这里是代码:decimald=96000000000000000000m;Dictionaryhashcount=newDictionary();in

c# - 为什么 C# 中没有 System.DateTime 的 "date"简写?

如int,long,ushort,uint,short,等等。为什么没有System.DateTime的简写? 最佳答案 Manytypesareassociatedwith"shorthand"keywordsinC#;forexample,System.Int32canalsobewrittenintandSystem.Stringcanbewrittenstring.Whyisn'tthereashorthandforSystem.DateTime?在我回答这个问题之前——或者更确切地说,没有回答它——让我们首先注意在C#中有