Dies ist ein Code-SnippetInstantiate eine Feldvariable
istpublic class CartItemList
{
//internal list of items and the constructor that instantiates it
private List<CartItem> **cartItems**;
public CartItemList() {
cartItems = new List<CartItem>();
ich fragen will, ist es möglich, cartItems Liste Konstruktor vor CartItemList starten() Konstruktor es instanziiert? und dann einfach den Standardkonstruktor von CartItemList verwenden?
So:
public class CartItemList
{
//internal list of items and the constructor that instantiates it
private List<CartItem> cartItems= new List<CartItem>();
public CartItemList()
Was ist das Problem? Hast du überhaupt versucht, diesen Code auszuführen? –
Bitte beachten Sie auch, dass dies * kein * Javascript ist, also nicht als lauffähiges JavaScript-Code-Snippet gekennzeichnet werden sollte. (Ich habe die Frage bearbeitet, um diese Tags zu entfernen und den Code zu formatieren.) –
@JonSkeet danke für den Kommentar, du hast Recht – mybirthname