OJ問題3486単純なクラスとメンバーインスタンス(C#)

タイトル説明

単純なクラスとメンバーインスタンス。次の図に示すようにクラスStudentを定義し、次の図と指定されたコードに従って不足しているコードを入力します。 
 
システムを使用して、
名前空間のサンプルは{     クラスの学生{         公共の文字列studentid; //は、学生数         パブリック文字列studentname; //名前         のプライベート文字列の発祥の地; //故郷         民間のDateTime生年月日、出生//日付         /         コードで//くださいフィルが達成するためにclass noパラメーターとパラメーター化されたコンストラクター、          //プロパティStudentId、StudentName、BirthPlace、BirthDate、Age         /     }     クラスProgram     {         static void Main(string [] args)         {             Student zs = new Student( "201753501234"、 "zs");             zs .BirthDate = DateTime.Parse( "1988-12-10");




















            zs.BirthPlace = "jinan";
            string s = "name:{0}、no:{1}、native:{2}、age:{3}";
            Console.WriteLine(s、zs.StudentName、zs.StudentId、zs.BirthPlace、zs.Age);
        }
    }

入る

番号

出力

出力名、学生番号、出身地、年齢、その他の情報 

サンプル入力

コピー

番号

サンプル出力

名前:zs、no:201753501234、ネイティブ:jinan、年齢:33

促す

1.年齢は読み取り専用属性です

。2。StudentId、Name StudentName、生年月日、BirthPlace、BirthPlaceは一般的な属性です。3。

コンストラクターには2つのタイプがあります。パラメーターの有無とパラメーターあり。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Student 
    {
        public string studentid;//学号
        public string studentname;//姓名
        private string birthplace;//籍贯
        private DateTime birthdate;//出生日期
        /
        //请填写代码,实现类的无参和有参构造函数、 
        public Student() { }
        public Student(string id,string name){
            studentid=id;
            studentname=name;
        }
        //属性StudentId、StudentName、BirthPlace、BirthDate、Age
        public string StudentId{
            get{
                return studentid;
            }
            set{
                studentid=value;
            }
        }
        public string StudentName{
            get{
                return studentname;
            }
            set{
                studentname=value;
            }
        }
        public string BirthPlace{
            get{
                return birthplace;
            }
            set{
                birthplace=value;
            }
        }
        public DateTime BirthDate{
            get{
                return birthdate;
            }
            set{
                birthdate=value;
            }
        }
        public int Age{
            get{
                return 33;
            }
        }
        /
    }
    class Program
    {
        static void Main(string[] args)
        {
            Student zs = new Student("201753501234", "zs");
            zs.BirthDate = DateTime.Parse("1988-12-10");
            zs.BirthPlace = "jinan";
            string s = "name:{0},no:{1},native:{2},age:{3}";
            Console.WriteLine(s,zs.StudentName,zs.StudentId,zs.BirthPlace,zs.Age);
        }
    }
} 

 

おすすめ

転載: blog.csdn.net/wangws_sb/article/details/105110829