C # Book Class implementations (questions have answers)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.