This is someone else's program, can only learn Coby first:
Using System;
Class Book {
Defining fields
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)//constructor, used the This keyword to emphasize the body
{
THIS.ISBN=ISBN;
This.titile=titile;
This.author=author;
this.press=press;
This.price=price;
}
Public Book (string ISBN): This (ISBN, "Unknown", "Unknown", "Unknown", 0) {}//question 1?????????? What you do with this is the constructor function
Explanation: Call the current class's own other constructors by: this after the constructor of the current class
Property accessors for adding attributes to fields
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 function
{
Console.WriteLine ("ISBN: {0}", ISBN);
Console.WriteLine ("title: {0}", Titile);
Console.WriteLine ("Author: {0}", author);
Console.WriteLine ("Publishing house: {0}", press);
Console.WriteLine ("Prices: {0}", price);
}
}
constructor function
Class callbook{
static void Main ()
{
Book Book1 = new book ("123456789");//Object
Book1. Show ();//function
Console.WriteLine ();
Book1. TITLE = "min";
Book1. AUTHOR = "Yes";
Book1. Press = "Ah";
Book1. Price = 12;
Book1. Show ();
Book1 = new book ("1236547", "Good", "Mountain", "up", 14);//Question 2?????????? No book here.
Can also implement object initialization is not very understanding
Book1. Show ();
Console.WriteLine ();
}
}
C # Book Class implementations (questions have answers)