RJIGO
RJIGO

Reputation: 1943

What data structure should I use?

Each of my object has these values: 2 short strings, 2 doubles and 5 TextBlocks (for a Windows app). I have about 30 of these objects.

I will need to iterate through these objects regularly. I have some ideas but want your independent suggestions for ease of iteration and selection of values from these objects.

One consideration is that the size of the collection is static, it doesn't need to grow.

Upvotes: 2

Views: 128

Answers (4)

Ankita Sen
Ankita Sen

Reputation: 434

Using Array of Objects........

enter code here
MyClass
{
   public string str;

   public SetStr(string st)
   {
     str=st;
   }

   public GetStr()
   {
      return str;
   }

}

int main() 
{ 
     MyClass obj[30]; 
     int i; 
     for(i=0; i < 30; i++) 
       obj[i].str; //Access as required
     return 0; 
}

Also for get and Set properies can be used

Upvotes: 3

Spencer
Spencer

Reputation: 375

Here's a link to information about LINQ - LINQ. LINQ is what you're looking for. Consider LINQ statements like the following example. Here is the syntax of LINQ:

var scores = new List<int>();
var Example =
        from score in scores
        where score > 80
        select score;

foreach (var example in Example) { doSomething(); }

The actual sorting only goes on when called at a later time. This is called deferred execution, one property of the example above. IE, Example's statement is only actually executed during:

 foreach (var example in Example) { doSomething(); }

There is also this to consider with LINQ:

Query syntax vs Method Syntax

I hope you have found this helpful.

Upvotes: 3

Shane Collins
Shane Collins

Reputation: 76

The properties in your object should not affect the type of collection you choose. The key is the fact that the number of items in your collection remains static, so a list is overkill. I would use a typed array like MyClass[]. You can still use LINQ to query the array and filter by any public property.

Upvotes: 6

iefpw
iefpw

Reputation: 7042

List with 3 different classes or strings. Generic class.

Upvotes: -1

Related Questions