这个控制台程序怎么写?
xmchw 2007-03-29 08:09:07 这个控制台程序怎么写? 在下面代码中在标题处如果输入为空,我提示他不能为空,继续输入标题,就是下面的注解部分?还有我输入完一本书,我提示他还是否要输入另外一本.如果选择Y 在重新输入谢谢
static void Main(string[] args)
{
ArrayList list = new ArrayList();
BookClass eBook = new BookClass();
Console.WriteLine("input book Title:");
string _title = Console.ReadLine(); //如果输入空有提示,但我还想停留在输入TITLE 这个行里面,不是跳到input book Author:",也就是输入空,就叫他一直输入,直到不为空为止.要怎么写?
eBook.Title = _title;
Console.WriteLine("input book Author:");
string _author = Console.ReadLine();
eBook.Author = _author;
Console.WriteLine("input book Cost:");
try
{
float _cost = float.Parse(Console.ReadLine().ToString());
eBook.Cost = _cost;
}
catch
{
Console.WriteLine("please input availibly float");
}
Console.WriteLine("input book Copies:");
try
{
int _copies = int.Parse(Console.ReadLine().ToString());
}
catch
{
Console.WriteLine("please input availibly int");
}
Console.ReadLine();
// list.Add(eBook);
// foreach (
}
class BookClass
{
private string title;
private string author;
private float cost;
private int copies;
public string Title
{
get
{
return title;
}
set
{
if (value == "")
{
Console.WriteLine("error, Title not allow null ,please input again");
}
else
{
title = value;
}
}
}
public string Author
{
get
{
return author;
}
set
{
if (value == "")
{
Console.WriteLine("error, Author not allow null ,please input again");
}
else
{
author = value;
}
}
}
public float Cost
{
get
{
return cost;
}
set
{
if (value ==float.NaN)
{
Console.WriteLine("error, Cost not allow null ,please input again");
}
else
{
cost = value;
}
}
}
public int Copies
{
get
{
return copies;
}
set
{
if (value==null )
{
Console.WriteLine("error, Copies not allow null ,please input again");
}
else
{
copies = value;
}
}
}
private void print()
{
Console.WriteLine("this book Title is "+title+" Author is "+ author +" Cost =" +cost.ToString()+ " Copies="+copies.ToString());
}
}