zoukankan      html  css  js  c++  java
  • c# BOOK类的实现(疑问有答案)

    这是别人的程序,只能先学习coby一下:

    using System;
    class BOOK {
    //定义字段
    private readonly string isbn;
    private string titile;
    private string author;
    private string press;
    private int price;
    public BOOK(string isbn,string titile,string author,string press,int price)//构造函数,用到了this关键字强调主体
    {
    this.isbn=isbn;
    this.titile=titile;
    this.author=author;
    this.press=press;
    this.price=price;
    }
    public BOOK(string isbn) : this(isbn, "未知", "未知", "未知", 0) { } //疑问1??????????用this干什么的 是构造函数

    //解释:在当前类的构造函数后面通过:this来调用当前类自己的其他构造函数


    //给字段加属性用属性访问器
    public string ISBN{
    get{
    return isbn;
    }
    }
    public string TITLE{
    get{
    return titile;
    }
    set{
    titile=value;
    }
    }
    public string AUTHOR{
    get{
    return author;}
    set{
    author=value;}
    }
    public string PRESS{
    get{
    return press;}
    set{
    press=value;}
    }
    public int PRICE{
    get{
    return price;}
    set{
    price=value;}
    }
    public void Show()//show函数
    {
    Console.WriteLine("书号:{0}",isbn);
    Console.WriteLine("标题:{0}",titile);
    Console.WriteLine("作者:{0}",author);
    Console.WriteLine("出版社:{0}",press);
    Console.WriteLine("价格:{0}",price);
    }


    }
    //构造函数
    class callbook{
    static void Main()
    {
    BOOK book1 = new BOOK("123456789");//对象
    book1.Show();//函数
    Console.WriteLine();
    book1.TITLE = "分";
    book1.AUTHOR = "是";
    book1.PRESS = "啊";
    book1.PRICE = 12;

    book1.Show();

    book1 = new BOOK("1236547", "好", "山", "了", 14);//疑问2?????????此处不用BOOK

    也能实现对象的初始化不是很懂

    book1.Show();
    Console.WriteLine();
    }
    }

  • 相关阅读:
    codeforces #601 div2 ABC~E1
    codeforces #600 div2 ABCD
    图形学 三次Hermite曲线绘制实现代码 javascript:es6+h5:canvas
    最小生成树(Prim / Kruskal)
    拓扑排序【Kahn算法(bfs)和dfs求拓扑序列及判环】
    Cow Traffic(正反向建图+DAG拓扑排序)
    JAVA大数
    【C/C++】关于strstr函数和c_str()函数
    【C/C++】关于函数调用传递实参
    2019上海icpc网络赛B. Light bulbs(思维+差分)
  • 原文地址:https://www.cnblogs.com/whyareyousocool/p/4332189.html
Copyright © 2011-2022 走看看