在用C#学习写一个最简单的图书借阅管理系统,想要实现输入一本书的数量后,如果数量大于0,“借阅状态”能判断为“可借阅”,反之则不可借阅,但是Qty用String类型无法用>来判断,改成int也报错,求问怎么改
public class Book
{
public string BookName { get; set; }
public string BookAuthor { get; set; }
public string BookQty { get; set; }
public string BookLoc { get; set; }
public string BookStatus { get; set; }
}
public class Library
{
List<Book> Books = new List<Book>();
List<Book> books = new List<Book>();
#region 录入
public void exe0()
{
int i = 1;
string str = "";
while (str != "ok")
{
Console.WriteLine("请输入第{0}本书的书名:", i);
string name = Console.ReadLine();
Console.WriteLine("请输入第{0}本书的作者:", i);
string author = Console.ReadLine();
Console.WriteLine("请输入第{0}本书的数量:", i);
string qty = Console.ReadLine();
Console.WriteLine("请输入第{0}本书的位置:", i);
string loc = Console.ReadLine();
if (qty > 0)
{
string status = "可借阅";
}
else
{
string status = "不可借阅";
}
Books.Add(new Book { BookName = name, BookAuthor = author, BookQty = qty, BookLoc = loc, BookStatus = status});
i = i + 1;
Console.WriteLine("输入 ok 停止录入,按任意键继续");
str = Console.ReadLine();
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("书名\t作者\t数量\t位置\t借阅状态");
foreach (var item in Books)
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", item.BookName, item.BookAuthor, item.BookQty, item.BookLoc, item.BookStatus);
}
}
运行报错
Operator '>' cannot be applied to operands of type 'string' and 'int'
The name 'status' does not exist in the current context