Put a struct into List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raulbolanos
    New Member
    • Apr 2009
    • 31

    Put a struct into List

    Hello,

    I want to put some structure into a List. Therefore I dont know how to declare the type list.. maybe structureType and then add the structure into the list, for example;

    Code:
    List<dataStructure> data = new List<dataStructure>();
    
    public struct dataStructure
    {
         string firstName;
         string lastName;
         string age;
         string address;        
    }
    what do you think? any recommendation?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Why are you using a struct instead of creating a class for this?

    Comment

    • cloud255
      Recognized Expert Contributor
      • Jun 2008
      • 427

      #3
      C# uses generics, similar to C++ templates, they are exactly what you're looking for.

      This MSDN entry explains how to use generics.

      Comment

      Working...