没有实例化也可以用this关键字吗?

来源:百度知道 编辑:UC知道 时间:2024/06/30 04:47:45
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1

{

class A
{
protected string Astr = "aaaaaaaaaaaaaaaaaaa";
}

class Program:A
{

static void Main(string[] args)

{
Program ee = new Program();
Console.Write(ee.u());
}

private string u()
{

return this.Astr;
}

}
}
---------------------------------------------------------
在这里 return this.Astr;加不加this,结果都可以访问到继承来的Astr.那想问的是,在这里加或不加有没有什么区别。还有就是this不是指代实例的吗,怎么这里在内类部没实例化的动作,也要用this.

这个函数被调用的时候,那显然是被实例化了,因为 u() 这个函数不是静态函数;而Main方法里面那个new单词已经告诉你实例化了。

你好好看看书或MSDN好不好?

http://msdn.microsoft.com/zh-cn/library/bcd5672a.aspx

类里面可以的