对象初始化表达式

来源:互联网 发布:sql修改字段绑定默认值 编辑:程序博客网 时间:2024/06/05 17:37

对象初始化表达式在构造函数中的应用:

using System;
using System.Collections.Generic;
using System.Text;
namespace Sample
{
    class Program
{
static viod Main()
{
//使用Exception类的过早函数实例化一个Exception对象
throw new exception("MyException"){ Source="LINQ Stduy"};
}
}
}




相同的逻辑但不使用对象初始化表达式


static viod Main()
{
//使用Exception类的构造函数实例化一个Exception对象
Exception exception = new Exception ("MyException");
exception.Source=" LINQ Study ";
throw exception;
}

0 0
原创粉丝点击