C# 我在类program1中有一个返回类型错误,返回类型为“1”;公共客户();错误

C# 我在类program1中有一个返回类型错误,返回类型为“1”;公共客户();错误,c#,C#,构造函数的名称应与类的名称相对应,因此重命名 using System; using System.Reflection; namespace Reflection { class Program { private static void Main(string[] args) { Type t = Type.GetType("program.program1"); Console.WriteLi

构造函数的名称应与类的名称相对应,因此重命名

using System;
using System.Reflection;

namespace Reflection
{
    class Program
    {
        private static void Main(string[] args)
        {
            Type t = Type.GetType("program.program1");
            Console.WriteLine(t.FullName);
            PropertyInfo[] p = t.GetProperties();
            foreach (PropertyInfo pr in p)
            {
                Console.WriteLine(pr.Name);
            }
        }
    }

    public class Program1
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Customer(int ID, string Name)
        {
            this.Id = ID;
            this.Name = Name; 
        }
        public Customer()
        {
            this.Id = -1;
            this.Name = string.Empty;
        }
        public void PrintId()
        {
            Console.WriteLine(this.Id);
        }
        public void PrintName()
        {
            Console.WriteLine(this.Name);
        }
    }
}
进入

  public class Program1 {...
  // class "Customer"...
  public class Customer {
    public int Id { get; set; }
    public string Name { get; set; }

    // Constructor has the same name that the class it creates
    public Customer(int ID, string Name)
    {
       this.Id = ID;
       this.Name = Name; 
    }

    // Constructor "Customer" has the same name that the class it creates
    public Customer()
    {
        this.Id = -1;
        this.Name = string.Empty;
    }

    public void PrintId()
    {
        Console.WriteLine(this.Id);
    }

    public void PrintName()
    {
        Console.WriteLine(this.Name);
    }
  }