using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class BookClass
{
private string title;
private string author;
private string subject;
private int book_id;
public void setValues(string t, string a, string s, int id)
{
title = t;
author = a;
subject = s;
book_id = id;
}
public void display()
{
Console.WriteLine("Title : {0}", title);
//Console.WriteLine("Author : {0}", author);
//Console.WriteLine("Subject : {0}", subject);
//Console.WriteLine("Book_id :{0}", book_id);
}
};
struct Bookstruct
{
private string title;
private string author;
private string subject;
private int book_id;
public void setValues(string t, string a, string s, int id)
{
title = t;
author = a;
subject = s;
book_id = id;
}
public void display()
{
Console.WriteLine("Title : {0}", title);
//Console.WriteLine("Author : {0}", author);
//Console.WriteLine("Subject : {0}", subject);
//Console.WriteLine("Book_id :{0}", book_id);
}
};
public class Class2
{
public static void Main(string[] args)
{
Bookstruct Book1 = new Bookstruct(); /* 声明 Book1,类型为 Books */
Bookstruct Book2 = new Bookstruct(); /* 声明 Book2,类型为 Books */
Book1.setValues("Book1", "Nuha Ali", "C Programming Tutorial", 6495407);
Book2.setValues("Book2","Zara Ali", "Telecom Billing Tutorial", 6495700);
Book1.display();
Book2.display();
Book2 = Book1;
Book2.setValues("Book2", "Zara Ali", "Telecom Billing Tutorial", 6495700);
Console.WriteLine("Book1.display():");
Book1.display();
Console.WriteLine("=====================");
BookClass book1 = new BookClass();
BookClass book2 = new BookClass();
book1.setValues("book1", "Nuha Ali", "C Programming Tutorial", 6495407);
book2.setValues("book2", "Zara Ali", "Telecom Billing Tutorial", 6495700);
book1.display();
book2.display();
book2 = book1;
book2.setValues("book2", "Zara Ali", "Telecom Billing Tutorial", 6495700);
Console.WriteLine("book1.display():");
book1.display();
Console.ReadKey();
}
}
}
/*
Title : Book1
Title : Book2
Book1.display():
Title : Book1
=====================
Title : book1
Title : book2
book1.display():
Title : book2
*/
评论已关闭