是否可以在列表中使用具有不同值的相同静态变量?如果我想使用不同的参数,我知道如果没有静态变量,代码会更好。这些是班级'我使用的变量。
public class book : IEquatable<book>
public string name { get; set; }
public string author { get; set; }
public static string themeName { get; set; }
public static List<book> allTheBooks = new List<book>();
public int bookID { get; set; }
构造
public book(string bookName, string bookAuthor, string theme, int bookID)
{
this.name = bookName;
this.author = bookAuthor;
this.bookID = bookID;
themeName = theme;
allTheBooks.Add(this);
}
稍后在代码中我创建了具有以下值的书籍
book book1 = new book("Cooking 3", "Chef the Wrapper", "Cooking", 0);
book book2 = new book("Modeling Models", "Matt McModel", "Fashion", 1);
book book3 = new book("100 different ways to fry", "Gorgon Fryman", "Cooking", 2);
book book4 = new book("Sea Sharp", "Unknown", "Coding", 3);
由于静态,现在每本书的主题都是编码。如果需要,我可以提供更多代码。
抱歉打字错误,我不是以英语为母语的人。提前致谢。