weixin_69158758 2022-05-05 21:29 采纳率: 100%
浏览 28
已结题

C#中赋完值在输出结果中不显示,谁知道怎么回事。

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#,给变量赋完值之后,输出结果不显示被赋的值,求指教怎么回事,实在搞不懂了

  • 写回答

1条回答 默认 最新

  • go_with_dream 2022-05-05 21:38
    关注

    输出打印的时候请用string.format("{0},{1},{2}",1,2,3)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月13日
  • 已采纳回答 5月5日
  • 创建了问题 5月5日

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据