對象引用對於非靜態的字段、方法、屬性Program.Print()是必需的


在學習重載是以下代碼報錯:

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

namespace 值類型1
{
    class Program
    {
        static void Main(string[] args)
        {
            Print();
        }
        public void Print()
        {
            Console.Write("Hello");
        }
        public void Print(string name)
        {
            Console.Write("Hello"+ name);
        }
    }
}

  解決方法  1>將方法定義為static  2> 實例化一個對象

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM