码迷,mamicode.com
首页 > 其他好文 > 详细

关键字:this

时间:2019-01-12 21:43:46      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:使用   cti   bsp   this关键字   main   linq   code   threading   new   

Class1.cs

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

namespace ConsoleApplication1
{
    class Class1
    {
        private string name;
        public Class1(string name)
        {
            // 使用this关键字表明使用当前对象的属性(或方法),后面的name是形参name
            this.name = name;
        }
        public void Eat()
        {
            Console.WriteLine("名字:" + this.name);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // 使用类
            Class1 myname = new Class1("namejr");
            myname.Eat();
        }
    }
}

 

关键字:this

标签:使用   cti   bsp   this关键字   main   linq   code   threading   new   

原文地址:https://www.cnblogs.com/namejr/p/10260959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!