A small case of book borrowing

Source: Internet
Author: User

This small case, the main practice of the creation and invocation of classes and methods

voidMain () { while(true) {Console.WriteLine ("Please enter a title or author"); varKey =Console.ReadLine ().            Trim (); Library.search (Key).        Dump (); Console.WriteLine ("Please enter the number of the book to be borrowed/returned"); varID =Convert.ToInt32 (Console.ReadLine ()); varBook =Library.search (ID);                Library.changestatus (book); Console.WriteLine ("do you want to continue? y/n"); if(Console.ReadLine (). ToLower ()! ="Y". ToLower ()) { Break; }    }}classlibrary{Private Static ReadOnlyList<book> Books =NewList<book>{        NewBook (1,"Red Mansions","Cao Xueqin", Status. has been returned),NewBook (2,"Journey to the","Wu Chengen", Status. has been returned),NewBook (3,"Outlaws","Shi Naian", Status. has been returned),NewBook (4,"Kingdoms","in Luo Guanzhong", Status. has been returned)};  Public StaticIenumerable<book> Search (stringkey) {        foreach(varBookinchBooks) {            if(Book. Title.contains (key) | |Book . Author.contains (key)) {yield returnBook ; }        }            }         Public StaticBook Search (intID) {        foreach(varBookinchBooks) {            if(Book. id==ID) {returnBook ; }        }        return NULL; }         Public Static voidchangestatus (book book) {if(book!=NULL)        {            if(Book. status==Status. Returned) {Console.WriteLine ("Book Lending success"); Book. Status=Status. has been borrowed; }Else{Console.WriteLine ("successful return of the book"); Book. Status=Status. has been returned; }        }    }}classbook{ Public intId;  Public stringTitle;  Public stringAuthor;  PublicStatus status;  PublicBook (intIdstringTitlestringauthor,status Status) {Id=ID; Title=title; Author=author; Status=status; }         Public stringInfo () {return string. Format ("Id:{0}\ttitle:{1}\tauthor:{2}\tstatus:{3}", Title,author,status); }}enumstatus{has been borrowed, has been returned}

A small case of book borrowing

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.