Create a Class named BooksDemo accepts and displays the details of books using multidimensional array.
BooksDemo
-colName:string[4] = {"BookTitle", "Author", "Publisher", "Price"}
-bookDetails: string[2,4]
+Main(args: string[])
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace C_SHARP
{
class BooksDemo
{
private string []colName = {"BookTitle", "Author", "Publisher", "Price"};
private string [,]bookDetails=new string[2,4];
/// <summary>
/// Constructor
/// </summary>
public BooksDemo() {
}
/// <summary>
/// Read Books
/// </summary>
public void ReadBooks()
{
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < colName.Length; i++)
{
Console.Write("Enter {0}: ", colName[i]);
bookDetails[j, i] = Console.ReadLine();
}
Console.Write("\n");
}
}
/// <summary>
/// Display Books
/// </summary>
public void DisplayBooks()
{
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < colName.Length; i++)
{
Console.Write("{0}: {1}\n", colName[i], bookDetails[j, i]);
}
Console.Write("\n");
}
}
static void Main(string[] args)
{
BooksDemo booksDemo = new BooksDemo();
booksDemo.ReadBooks();
booksDemo.DisplayBooks(); ;
Console.ReadKey();
}
}
}
Comments
Leave a comment