• C#的初始化器


    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Reflection;
    using System.Text.RegularExpressions;
    using System.Linq;
    
    namespace codeTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                MyClass myClass1 = new MyClass() { FristName = "myClass1", LastName = "LmyClass1" };
                MyClass myClass2 = new MyClass("myClass2", "LmyClass2");
                MyClass myClass3 = new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 };
                myClass1.Show();
                myClass2.Show();
                myClass3.Show();
                List<MyClass> list = new List<MyClass>()
                {
                   new MyClass() { FristName = "myClass1", LastName = "LmyClass1" },
                   new MyClass("myClass2", "LmyClass2"),
                   new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 }
                };
                Dictionary<int, MyClass> dic = new Dictionary<int, MyClass>()
                {
                    {1,new MyClass() { FristName = "myClass1", LastName = "LmyClass1" }} ,
                    {2,new MyClass("myClass2", "LmyClass2")} ,
                    {3,new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 }} 
                };
                Console.ReadLine();
            }
    
    
        }
    
    
    
        public class MyClass
        {
            public string FristName;
            public string LastName { get; set; }
            public int id { get; set; }
    
            public MyClass()
            { }
    
            public MyClass(string frist,string last)
            {
                FristName = frist;
                LastName = last;
            } 
    
            public void Show()
            {
                Console.WriteLine("FristName:{0} LastName:{1} id:{2}", FristName, LastName, id);
            }
        }
    
    
    
    }
  • 相关阅读:
    一次聚类引发的一系列问题(工作经验篇)
    SQLServer数据库返回错误的国际化
    记一次SQL优化
    java设计模式-工厂模式(springweb为例子)
    JAVA中的泛型(Generic)
    spring源码分析-core.io包里面的类
    java设计模式-代理模式
    javaWeb正则表达式
    Java中的泛型
    关于API,前后端分离
  • 原文地址:https://www.cnblogs.com/lgxlsm/p/4790480.html
Copyright © 2020-2023  润新知