sing System;
using System.Collections.Generic;
using System.Text;namespace ConstructorDemo
{
class student
{
public string ID;
public string Name;
public int Age;
public Student()
{
ID = "空";
Name = "空";
Age = "0";
}
public Student(string id, string name, int age)
{
ID = id;
Name = name;
Age = age;
}
public void ShowStudent()
{
Console.WriteLine("学号:{0},姓名:{1},年龄:{2}", ID, Name, Age);
}
}
class Program
{
static void Main(string[] args)
{
Student stu1 = new Student();
stu1.ShowStudent();
Student stu2 = new Student("090304121","万文渊",20);
stu2.ShowStudent(); }
}
}
错误提示:错误 1 类、结构或接口方法必须有返回类型 F:\PROGRAM\C#\Error Program of C#\ConstructorDemo\ConstructorDemo\Program.cs 12 16 ConstructorDemo
错误 2 类、结构或接口方法必须有返回类型 F:\PROGRAM\C#\Error Program of C#\ConstructorDemo\ConstructorDemo\Program.cs 18 16 ConstructorDemo
using System.Collections.Generic;
using System.Text;namespace ConstructorDemo
{
class student
{
public string ID;
public string Name;
public int Age;
public Student()
{
ID = "空";
Name = "空";
Age = "0";
}
public Student(string id, string name, int age)
{
ID = id;
Name = name;
Age = age;
}
public void ShowStudent()
{
Console.WriteLine("学号:{0},姓名:{1},年龄:{2}", ID, Name, Age);
}
}
class Program
{
static void Main(string[] args)
{
Student stu1 = new Student();
stu1.ShowStudent();
Student stu2 = new Student("090304121","万文渊",20);
stu2.ShowStudent(); }
}
}
错误提示:错误 1 类、结构或接口方法必须有返回类型 F:\PROGRAM\C#\Error Program of C#\ConstructorDemo\ConstructorDemo\Program.cs 12 16 ConstructorDemo
错误 2 类、结构或接口方法必须有返回类型 F:\PROGRAM\C#\Error Program of C#\ConstructorDemo\ConstructorDemo\Program.cs 18 16 ConstructorDemo
解决方案 »
- the UpdateCommand affected 0 of the expected 1 records请帮忙解决,谢谢
- Session与HttpContext.Current.Session到底有什么区别呢?
- 怎么获取特定的日期时间距今多少分钟?
- splitContainer1.Panel1
- 无法显示XML页???
- 去除SortedList重复的键值
- 请问,ASP.NET(C#)里怎么样用代码实现对sqlserver调用select存储过程??
- 大家好,小弟有一个问题需要请教了!C#中XML字符串加载到Recordset的问题!
- BindingSource控件的DataSource属性为什么是类型而不是实例?
- 索引超出数组界限,求助!!
- c# 获取当前实例的问题
- 如何解决二元方程组问题
sing System;
using System.Collections.Generic;
using System.Text;namespace ConstructorDemo
{
class student
{
public string ID;
public string Name;
public int Age;//Age定义成int型
public Student()//这个我想你是构造函数,既然构造函数就要跟你的类名一样,也就是Student改成小写
{
ID = "空";
Name = "空";
Age = "0";//你却给他赋值字符串
}
public Student(string id, string name, int age)
{
ID = id;
Name = name;
Age = age;
}
public void ShowStudent()
{
Console.WriteLine("学号:{0},姓名:{1},年龄:{2}", ID, Name, Age);
}
}
class Program
{
static void Main(string[] args)
{
Student stu1 = new Student();
stu1.ShowStudent();
Student stu2 = new Student("090304121","万文渊",20);
stu2.ShowStudent(); }
}
}