I am currently following tutorials on c# as I am a c++ programmer, and am wanting to see what all the .NET talk is about with c# ;). Here is what I want my program to do. It asks the user to input title, author, subject, and bookID for 3 books (or however many I set the loop for).
I am a bit confused with the usage of the foreach loop. Can someone lend me a hand here please ?
Thank you!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class StringProg
{
struct book
{
public string title;
public string author;
public string subject;
public int bookID;
public void Getinfo()
{
Console.WriteLine("Please enter the title of the book:");
title = Console.ReadLine();
Console.WriteLine("Please enter the author of the book:");
author = Console.ReadLine();
Console.WriteLine("Please enter the subject of the book:");
subject = Console.ReadLine();
Console.WriteLine("Please enter the book ID of the book:");
bookID = Convert.ToInt32(Console.ReadLine());
}
public void Display()
{
Console.Clear();
Console.WriteLine("This is the information for the book you entered:\n\n");
Console.WriteLine(title);
Console.WriteLine(author);
Console.WriteLine(subject);
Console.WriteLine(bookID);
}
}
static void Main(string[] args)
{
book[] books = new book[3];
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Getting book information for book #:{0}\n\n", i);
foreach(int j in books[i])
{
books[j].Getinfo();
books[j].Display();
}
}
Console.ReadLine();
}
}
}