求解c#
时间:2011-09-04
来源:互联网
各位前辈,我是一个初出学者,现在遇到一个问题,急需解答
问题如下 :、
using System;
using System.Collections.Generic;
using System.Text;
namespace 构造函数.控制类台
{
class Program
{
static void Main(string[] args)
{
class Student //采用命名法,第一个字母大写
{
int age; //字段名小写
string name;
}
//这是构造函数,他的功能是给字段进行初始值,此外,构造函数是方法的一种,注意他的命名方式
public void Student()
{
name="赵本山";
age=0;
}
//函数方法可以重载
public void Student(string name,int age)
{
this .name=name; //this为相应的对象或变量
this.age=age;
}
//方法
public void PrintStudent() //注意命名的方式
{
Console.WriteLine("{0},{1}years old:",name,age);
}
}
class Test
{
static void Main()
{
//使用new 建立类的对象
Student student1=new Student("郭美美","20");
Student student2=new Student("潺潺","10");
Student student3=new Student();
Console.WriteLine("student#1");
student1.PrintStudent();
Console.WriteLine("student#2");
student2.PrintStudent();
Console.WriteLine("student#3");
student2.PrintStudent();
}
}
}
}
}
检查了很多遍,就是不知道出现什么问题,希望各位前辈指点,在此先谢过啦!!
问题如下 :、
using System;
using System.Collections.Generic;
using System.Text;
namespace 构造函数.控制类台
{
class Program
{
static void Main(string[] args)
{
class Student //采用命名法,第一个字母大写
{
int age; //字段名小写
string name;
}
//这是构造函数,他的功能是给字段进行初始值,此外,构造函数是方法的一种,注意他的命名方式
public void Student()
{
name="赵本山";
age=0;
}
//函数方法可以重载
public void Student(string name,int age)
{
this .name=name; //this为相应的对象或变量
this.age=age;
}
//方法
public void PrintStudent() //注意命名的方式
{
Console.WriteLine("{0},{1}years old:",name,age);
}
}
class Test
{
static void Main()
{
//使用new 建立类的对象
Student student1=new Student("郭美美","20");
Student student2=new Student("潺潺","10");
Student student3=new Student();
Console.WriteLine("student#1");
student1.PrintStudent();
Console.WriteLine("student#2");
student2.PrintStudent();
Console.WriteLine("student#3");
student2.PrintStudent();
}
}
}
}
}
检查了很多遍,就是不知道出现什么问题,希望各位前辈指点,在此先谢过啦!!
作者: chengnuo628 发布时间: 2011-09-04
namespace 构造函数.控制类台
{
class Student //采用命名法,第一个字母大写
{
int age; //字段名小写
string name;
//这是构造函数,他的功能是给字段进行初始值,此外,构造函数是方法的一种,注意他的命名方式
public Student()
{
name="赵本山";
age=0;
}
//函数方法可以重载
public Student(string name,int age)
{
this .name=name; //this为相应的对象或变量
this.age=age;
}
//方法
public void PrintStudent() //注意命名的方式
{
Console.WriteLine("{0},{1}years old:",name,age);
}
}
class Test
{
static void Main()
{
//使用new 建立类的对象
Student student1=new Student("郭美美",20);
Student student2=new Student("潺潺",10);
Student student3=new Student();
Console.WriteLine("student#1");
student1.PrintStudent();
Console.WriteLine("student#2");
student2.PrintStudent();
Console.WriteLine("student#3");
student2.PrintStudent();
}
}
}
一,Main函数只能一个
二,构造函数没有返回值
{
class Student //采用命名法,第一个字母大写
{
int age; //字段名小写
string name;
//这是构造函数,他的功能是给字段进行初始值,此外,构造函数是方法的一种,注意他的命名方式
public Student()
{
name="赵本山";
age=0;
}
//函数方法可以重载
public Student(string name,int age)
{
this .name=name; //this为相应的对象或变量
this.age=age;
}
//方法
public void PrintStudent() //注意命名的方式
{
Console.WriteLine("{0},{1}years old:",name,age);
}
}
class Test
{
static void Main()
{
//使用new 建立类的对象
Student student1=new Student("郭美美",20);
Student student2=new Student("潺潺",10);
Student student3=new Student();
Console.WriteLine("student#1");
student1.PrintStudent();
Console.WriteLine("student#2");
student2.PrintStudent();
Console.WriteLine("student#3");
student2.PrintStudent();
}
}
}
一,Main函数只能一个
二,构造函数没有返回值
作者: qzp000000 发布时间: 2011-09-04
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28