Arrays 在控制台程序中使用委托数组时出错
您好,您好,下面的每一个都是我正在制作的程序。这个程序的目的是简单地获取输入和输出…但是这个错误正在发生 错误1“方法”不包含接受“0”参数的构造函数Arrays 在控制台程序中使用委托数组时出错,arrays,delegates,instances,Arrays,Delegates,Instances,您好,您好,下面的每一个都是我正在制作的程序。这个程序的目的是简单地获取输入和输出…但是这个错误正在发生 错误1“方法”不包含接受“0”参数的构造函数 using System; using System.Collections.Generic; using System.Linq; using System.Text; public delegate void method(); namespace Question5 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public delegate void method();
namespace Question5
{
public class student
{
private int Reg;
private int course;
private float gpa;
private string Batch;
private string Name;
public void Setpersonalinfo()
{
Console.WriteLine("Enter The Name:");
Name =Console.ReadLine();
Console.WriteLine("Enter The Reg Num:");
Reg = int.Parse(Console.ReadLine());
Console.WriteLine("Enter The Batch:");
Batch = Console.ReadLine();
}
public void getpersonalinfo()
{
Console.WriteLine("Entered Name : {0}",Name);
Console.WriteLine("Entered Reg Num: {0}",Reg);
Console.WriteLine("Entered Batch: {0}",Batch);
}
public void setcourseinfo()
{
Console.WriteLine("How many courses you have Registered?");
course = int.Parse(Console.ReadLine());
}
public void getcourseinfo()
{
Console.WriteLine("Your registered courses are: {0}",course);
}
public void setgpa()
{
Console.WriteLine("Pl Enter you GPA ");
gpa = float.Parse(Console.ReadLine());
}
public void getgpa()
{
Console.WriteLine("Your GPA is: {0}",gpa);
}
static void Main(string[] args)
{
//int num;
student s1 = new student();
//Console.WriteLine("For how Many Students you want to enter record?");
//num = int.Parse(Console.ReadLine());
method[] d1 = new method[2];
for (int i = 0; i < d1.Length; i++)
d1[i] = new method();
for(int i=0;i<2;i++)
{
Console.WriteLine("Enter The Personal Details:");
d1[i] = new method(s1.Setpersonalinfo);
Console.WriteLine("Enter The Courses:");
d1[i] = new method(s1.setcourseinfo);
Console.WriteLine("Enter The GPA:");
d1[i] = new method(s1.setgpa);
}
for (int i = 0; i <2; i++)
{
Console.WriteLine("Your Entered all details are:");
d1[i] = new method(s1.getpersonalinfo);
d1[i] = new method(s1.getcourseinfo);
d1[i] = new method(s1.getgpa);
}
Console.ReadLine();
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
公共委托无效方法();
名称空间问题5
{
公立班学生
{
私人int注册;
私人综合课程;
私人浮动gpa;
私有字符串批处理;
私有字符串名称;
public void Setpersonalinfo()
{
Console.WriteLine(“输入名称:”);
Name=Console.ReadLine();
Console.WriteLine(“输入注册表号:”);
Reg=int.Parse(Console.ReadLine());
Console.WriteLine(“输入批次:”);
Batch=Console.ReadLine();
}
public void getpersonalinfo()
{
WriteLine(“输入的名称:{0}”,名称);
WriteLine(“输入的注册表编号:{0}”,注册表);
WriteLine(“输入的批:{0}”,批);
}
公共无效setcourseinfo()
{
Console.WriteLine(“您注册了多少课程?”);
course=int.Parse(Console.ReadLine());
}
公共无效getcourseinfo()
{
WriteLine(“您注册的课程是:{0}”,课程);
}
公共无效setgpa()
{
Console.WriteLine(“Pl输入GPA”);
gpa=float.Parse(Console.ReadLine());
}
public void getgpa()
{
WriteLine(“您的GPA是:{0}”,GPA);
}
静态void Main(字符串[]参数)
{
//int-num;
学生s1=新学生();
//WriteLine(“您想输入多少学生的记录?”);
//num=int.Parse(Console.ReadLine());
方法[]d1=新方法[2];
对于(int i=0;i 对于(int i=0;i而不是使用代理数组
,请使用多播代理
。
更改main
方法,如下所示
student s1 = new student();
method d;
d = new method(s1.Setpersonalinfo);
d += new method(s1.setcourseinfo);
d += new method(s1.setgpa);
d += new method(s1.getpersonalinfo);
d += new method(s1.getcourseinfo);
d += new method(s1.getgpa);
for (int i = 0; i < 2;i++ )
d();
Console.ReadKey();
student s1=新学生();
方法d;
d=新方法(s1.Setpersonalinfo);
d+=新方法(s1.setcourseinfo);
d+=新方法(s1.setgpa);
d+=新方法(s1.getpersonalinfo);
d+=新方法(s1.getcourseinfo);
d+=新方法(s1.getgpa);
对于(int i=0;i<2;i++)
d();
Console.ReadKey();