using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 练习题2
{ class Student
{
string name;
char sex;
int age;
int math;
int language;
int english;
public int English
{
get { return english; }
set { english = value >= 0 ? value : 0; ; }
}
public int Language
{
get { return language; }
set { language = value >= 0 ? value : 0; }
}
public int Math
{
get { return math; }
set
{
age = value >= 0 ? value : 0;
}
}
public string Name
{
get { return name; }
set { name = value; }
}
public char Sex
{
get { return sex; }
set
{
if (value == '男' || value == '女')
{
sex = value;
}
else
{
sex = '男';
}
}
}
public int Age
{
get
{ return age; }
set
{
if (value >= 0)
{
age = value;
}
else
{
age = 0;
}
}
}
public void SayHello()
{
Console.WriteLine("我叫(0),我是(1)生,我今年(2)岁",name,sex,age);
}
public void Showscore()
{
int sum = math + language + english;
float avg = sum / 3;
Console.WriteLine("我叫(0),我的总成绩是(1),我的平均成绩是(2)",name,sum,avg);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 练习题2
{
class Program
{
static void Main(string[] args)
{
Student zsStudent = new Student();
zsStudent.Name = "张三";
zsStudent.Age = 18;
zsStudent.Sex ='男';
zsStudent.Language = 90;
zsStudent.Math = 95;
zsStudent.English = 85;
Student xlStudent = new Student();
xlStudent.Name = "小兰";
xlStudent.Age = 18;
xlStudent.Sex = '女';
xlStudent.Language = 90;
xlStudent.Math = 100;
xlStudent.English = 90;
Console.WriteLine("下面是张三的");
zsStudent.SayHello();
zsStudent.Showscore();
Console.WriteLine("下面是小兰的");
xlStudent.SayHello();
xlStudent.Showscore();
Console.ReadKey();
}
}
}
刚开始学C#,给变量赋完值之后,输出结果不显示被赋的值,求指教怎么回事,实在搞不懂了