Declaring and Using Global Arrays c#

前端 未结 8 2083
星月不相逢
星月不相逢 2020-12-30 12:02

I couldn\'t find any information pertaining to this question. I am trying to create a global array in C# so that I can input information into it at different points in my co

8条回答
  •  离开以前
    2020-12-30 12:28

    I don't suggest you to use global arrays, is not a best practice what you would need is a data repository and take from there the data you want to use, regarding the structure you want to use I suggest you to do something like this:

    public class Auction
    {
               public string auctionID {get; set;}
               public string itemName {get; set;}
               public string itemID {get; set;}
               public string bid {get; set;}
               public string buyout {get; set;}
               public int quantity {get; set;} 
    }
    

    And then use a List of that particular object to access your data.

    List acutions = new List();
    

    Then you can add or remove items as desired.

    auctions.Add(auction object);
    auctions.remove(auction object);
    

    Or navigate through the list with a foreach loop

    foreach (Auction item in auctions)
    {
     // your code to handle items here
    }
    

提交回复
热议问题