文章分类 - .NET
摘要:implicit:自定义类型隐式转换。explict:自定义类型强制转换。 class Program { static void Main(string[] args) { Currency currency = new Currency(1...
阅读全文
posted @ 2015-05-08 15:11
江境纣州
摘要:class Program { static void Main(string[] args) { someclass x = new someclass(); int hashCode = RuntimeHelp...
阅读全文
posted @ 2015-05-08 13:40
江境纣州
摘要:static void Main(string[] args) { long val = 30000000000; try { checked ...
阅读全文
posted @ 2015-05-08 13:17
江境纣州
摘要:以前学多维数组的时候,看到有int[,]和int[][]两种表示方式,一:int[,] myarr = new int[,]{{1,2,3},{4,5,6},{7,8,9}};可以。int[,] myarr = new int[1,2];可以二:int[][] myarr = new int[][]...
阅读全文
posted @ 2015-05-05 15:02
江境纣州
摘要:public class WroxDynamicObject : DynamicObject { private Dictionary _dynamicData = new Dictionary(); /// /// 获取成员值的操作提供实现 ...
阅读全文
posted @ 2015-05-05 14:26
江境纣州
摘要:1、什么是强类型: 强类型相对于dynamic,就是在编译器就检查变量的类型。强类型相对于弱类型,没有强制类型转换,不允许两个不同类型的变量进行相互操作。 2、什么是类型安全: 类型安全需要有两个因数:一个就是良好的数据类型,强类型;一个就是垃圾回收机制。 3、什么是委托: 委托就是方法的类型安全的
阅读全文
posted @ 2015-05-05 10:31
江境纣州
摘要:1.上次面试问到DataTable在多线程下的操作。现在想想用lock吧。【lock(objectA){codeB} 看似简单,实际上有三个意思,这对于适当地使用它至关重要:1. objectA被lock了吗?没有则由我来lock,否则一直等待,直至objectA被释放。2. lock以后在执行co...
阅读全文
posted @ 2015-04-24 17:53
江境纣州
摘要:在学习特性的AttributeUsage时,自己写代码,写着写着变成[AttributeUsage(AttributeTargets.Class || AttributeTargets.Property || AttributeTargets.Method)]然后发现编译出错了。仔细一看操作符出错了...
阅读全文
posted @ 2015-04-24 13:15
江境纣州
摘要:1.自动属性: public class Person { public int Id { get; set; } public string Name { get; set; } } 2.隐式类型: 编译器会根据赋值变量自动判断隐式类型的类型,类型确定后不可以更改,变量声明需要初始化,且不能为nu
阅读全文
posted @ 2015-04-23 16:41
江境纣州
摘要:1. routes.MapRoute( "Default", // 路由名称 "{controller}/{action}/{id}", // 带有参数的 URL new { controller = "Movie", action = "Details", id = "2" } // 参数默认值
阅读全文
posted @ 2015-04-23 16:13
江境纣州
摘要:1.内存上: class是引用类型,内存在分配在堆中,内存由垃圾回收机制回收,所以有析构函数。 struct是值类型,内存分配在栈中,但可以实现接口,struct变量使用完之后自动释放内存分配,说以没有析构函数。 2.继承上: class支持继承自类和接口;而struct只能支继承接口。 class
阅读全文
posted @ 2015-04-22 20:01
江境纣州
摘要:/// /// 入口方法 /// public static void Main() { ExceptionClass ec = new ExceptionClass(); try ...
阅读全文
posted @ 2015-04-18 13:32
江境纣州
摘要:1.建一个wcf服务应用程序:2.定义一个提供wcf服务的接口和数据契约:namespace WcfService1{ // 服务合同 即提供服务的接口或类 [ServiceContract] public interface IService1 { [Ope...
阅读全文
posted @ 2015-04-17 15:00
江境纣州
摘要:约束类: class Program { static void Main(string[] args) { List<Account> list = new List<Account>(); list.Add(new Account("张三", 156345.5M)); list.Add(new
阅读全文
posted @ 2015-04-14 19:49
江境纣州
摘要:class Program { static void Main(string[] args) { Person p1 = new Person("张三"); Person p2 = new Person("李思思"); Console.WriteLine(p1.CompareTo(p2)); Ca
阅读全文
posted @ 2015-04-14 16:42
江境纣州
摘要:以前知道where T:class 和where T:struct的作用是约束T是自定义类类型还是值类型; 还有就是where T:new()的作用是约束必须有一个无参的构造函数。 但是对于where T:IFoo和where T:Foo,就只知道有这么一个约束,自己也没深入研究过,而且自己写的泛型
阅读全文
posted @ 2015-04-14 16:29
江境纣州
摘要:class Program { static void Main(string[] args) { int i = Calculator.Add(1, 2); double d = Calculator.Add(1.2, 3.2); string s = Calculator.Add("ab", "
阅读全文
posted @ 2015-04-13 16:53
江境纣州