關於c#中的多態問題,在父類的方法中我如何能調用到子類的屬性?

 我在c#中實現以下代碼:c#

using System;
namespace HelloWorldApplication
{

	class A{
	    public string s = "1";
		
		public string getS(){ return this.s;}
	}
	
	class B:A{
	 	public new string s = "a";
	}
    class HelloWorld
    {
        static void Main(string[] args)
        {
            /* 個人第一個 C# 程序*/
			B a = new B();
            Console.WriteLine(a.getS());
            Console.ReadKey();
        }
    }
}

上面代碼運行的結果始終是"1",我如何能讓運行結果變成"a"this

在父類的方法中我如何能調用到子類的屬性?spa

相關文章
相關標籤/搜索