這可能是一個noob問題,但我仍然需要問它。考慮下面兩個類未分配的屬性在類中佔用內存嗎?
public class Book{
public string Title;
public string Author;
public string ISBN;
public DateTime Published;
public string Description;
public string Genre;
public float Price
public int Pages;
public Book(){
}
}
public class BookStub{
public string Title;
public string Author;
public BookStub(){
}
}
如果我通過以下方式
Book a = new Book{
Title = "Do Androids Dream of Electric Sheep?",
Author = "Philip K. Dick"
};
BookStub b = new BookStub{
Title = "Do Androids Dream of Electric Sheep?",
Author = "Philip K. Dick"
};
難道這兩種情況下佔用的內存量相同創建的每個類的實例?還是第一個佔用更多?