摘要:做了一个小测试,按照beautyispower原来的代码: using System;using System.Text;namespace Test{public class TestApp{ public static void Main( string[] args ) { int intTimeUsed=0; int intCount=0; int intMaxCount...
阅读全文
摘要:String s = “Hello”;Console.WriteLine(Object.ReferenceEquals(“Hello“,s));你猜显示是true还是false,很多人会猜false,你看,不是有两个“Hello”对象吗?可实际上应该是true,为什么呢?下面解释一下:其实CLR初始化时,他会创建一个内部散列表,键为字符串,值为指向托管堆中字符串对象的引用。刚开始这个表是空的。当J...
阅读全文
摘要:假设我们需要XML,但是不想要SOAP特有的额外信息,应该怎么办?我们可以使用类库XMLSerializer。代码如下: using System;using System.IO;using System.Xml.Serialization;//[Serializable]public class Insect{ public string name; //[NonSeria...
阅读全文
摘要:原作者:Alex Farber 原文:http://www.codeproject.com/csharp/DrawTools.asp(源代码请参见原文) Introduction DrawTools sample shows how to create a Windows Forms application for drawing graphic objects in a Windows clie...
阅读全文
摘要:默认情况下,所有属性都是单次使用的。所以编译一下代码会得到一个编译器错误。 using System;public class SomethingAttribute : Attribute{ public SomethingAttribute(String str) { }}//Error[Something("abc")][Something("def")]class MyC...
阅读全文
摘要:原作者:Kevin Stewart 文章出处:http://www.codeproject.com/csharp/pwdgen.asp Introduction This article illustrates how to create a very simple password generator using C#. Password generators are useful in ma...
阅读全文
摘要:原作者:Nishant S Introduction Just about everything is a heap object when you are using C#. Only elementary native types like int are treated as value types. But there are two value types in C# that are...
阅读全文
摘要:如前一节所述,RegKeyAttribute属性构造器为:public RegKeyAttribute(RegHives Hive, String ValueName)根据这个属性构造器原型,我们把这个属性附着给一个字段:[RegKey(RegHives.HKEY_CURRENT_USER, "Foo")] public int Foo;其实可以使编程更加容易。如果参数在大多数情况下不变,可以使...
阅读全文
摘要:6.3.2 方法属性 using System;using System.Reflection;namespace MethodAttribs{ public class TransactionableAttribute : Attribute { public TransactionableAttribute() { } } ...
阅读全文