.Net3.0中的自动属性(示例)
 using System;
using System;
 namespace LinqDemo
namespace LinqDemo {
{
 class Program
    class Program {
    { static void Main(string[] args)
        static void Main(string[] args) {
        { //传统用法示例
            //传统用法示例 Employee Emp = new Employee("Jimmy.Yang", 25);
            Employee Emp = new Employee("Jimmy.Yang", 25); Console.WriteLine(Emp.ToString());
            Console.WriteLine(Emp.ToString());
 Console.WriteLine("-------------------");
            Console.WriteLine("-------------------");
 //自动属性的写法
            //自动属性的写法 NewEmployee NewEmp = new NewEmployee { Name = "Tom", Age = 30 };//感觉与Javascript中对象的JSON字符串表示法相似
            NewEmployee NewEmp = new NewEmployee { Name = "Tom", Age = 30 };//感觉与Javascript中对象的JSON字符串表示法相似 Console.WriteLine(NewEmp.ToString());
            Console.WriteLine(NewEmp.ToString());
 Console.ReadLine();
            Console.ReadLine(); }
        }        }
    }

 /// <summary>
    /// <summary> /// 传统方式定义一个类
    /// 传统方式定义一个类 /// </summary>
    /// </summary> public class Employee
    public class Employee {
    { private string _name = "Anonymous";
        private string _name = "Anonymous"; private int _age = 0;
        private int _age = 0;
 public string Name
        public string Name  {
        { get { return this._name; }
            get { return this._name; } set { this._name = value; }
            set { this._name = value; } }
        }
 public int Age
        public int Age  {
        { get { return this._age; }
            get { return this._age; } set { this._age = value; }
            set { this._age = value; } }
        }
 public Employee() { }
        public Employee() { }
 public Employee(string pName, int pAge)
        public Employee(string pName, int pAge)  {
        { this._name = pName;
            this._name = pName; this._age = pAge;
            this._age = pAge; }
        }
 public override string ToString()
        public override string ToString() {
        { return "Name:" + this._name + " Age:" + this._age;
            return "Name:" + this._name + " Age:" + this._age; }
        } }
    }

 /// <summary>
    /// <summary> /// .Net3.0自动属性的新写法
    /// .Net3.0自动属性的新写法 /// </summary>
    /// </summary> public class NewEmployee
    public class NewEmployee {
    { public string Name{get; set;}
        public string Name{get; set;} public int Age { get; set; }
        public int Age { get; set; } public override string ToString()
        public override string ToString() {
        { return "Name:" + this.Name + " Age:" + this.Age;
            return "Name:" + this.Name + " Age:" + this.Age; }
        } }
    } }
}
 <script type="text/javascript">
<script type="text/javascript"> var Emp = {Name:"Jimmy.Yang",Age:30};
var Emp = {Name:"Jimmy.Yang",Age:30};
 function ShowEmp(E)
function ShowEmp(E) {
{ return "Name:" + E.Name + " Age:" + E.Age;
    return "Name:" + E.Name + " Age:" + E.Age; }
}
 document.write(ShowEmp(Emp));
document.write(ShowEmp(Emp));
 </script>
</script>顺便发表一下个人感慨:微软确实很善于吸引他人长处
作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
 
                    
                

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号