方法、属性的使用

来源:互联网 发布:摄像头图像处理算法 编辑:程序博客网 时间:2024/06/16 12:42
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{    class Program    {        static void Main(string[] args)        {            Student st1 = new Student();//无参构造函数            st1.Name = "江涛";            st1.Score = 890;            st1.Score += 10;            Console.WriteLine("无参构造函数输出结果是:" + st1.GetInfo());            Student st2 = new Student("江涛", 890);//有参函数            Console.WriteLine("有参构造函数输出结果是:" + st2.GetInfo());            Console.ReadLine();        }    }}class Student{    public string Name { get; set; }//属性    public float Score { get; set; }//方法    public string GetInfo()//    {        return "姓名:" + Name + ",分数:" + Score.ToString() + "\n";    }    public Student(string name, float score)    {        Name = name;        Score = score;    }    public Student() { }}

0 0