C#构造方法--实例化类时初始化的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            a a1 = new a();

            Console.ReadKey();
        }
    }
    class a
    {
        public a()//定义一个构造方法
        {
            Console.Write("1");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            a a1 = new a("1");

            Console.ReadKey();
        }
    }
    class a
    {
        public a(string str)//定义一个构造方法
        {
            Console.Write(str);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            a a1 = new a("1");

            Console.ReadKey();
        }
    }
    class a
    {
        /*
        public a()//如果自己不写那么默认这个
        { 
            
        }
        */
        public a(string str)//定义一个构造方法
        {
            Console.Write(str);
        }
    }
}

原文地址:https://www.cnblogs.com/yangfengwu/p/5864625.html