what is 'this' constructor, what is it for

前端 未结 4 989
臣服心动
臣服心动 2020-11-30 15:43

I\'m in the learning process and I have a question I havent been able to find a satisfactory answer for.

this I need a rundown on it. I keep seeing it a

4条回答
  •  庸人自扰
    2020-11-30 16:27

    It's used to invoke another constructor in the class:

    public class Test {
        public Test() : this("AmazingMrBrock")
        {
    
        }
    
        public Test(string name) 
        {
           Console.WriteLine(name);
        }
    
    }
    

    http://msdn.microsoft.com/en-us/library/vstudio/ms173115.aspx

提交回复
热议问题