C Sharp Programming/Data structures

There are various ways of grouping sets of data together in C#.
Enumerations.
An "enumeration" is a data type that "enumerates" a set of items by assigning to each of them an identifier (a name), while exposing an underlying base type for ordering the elements of the enumeration. The underlying type is by default, but can be any one of the integral types except for .
Enumerations are declared as follows:
 enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
The elements in the above enumeration are then available as constants:
 Weekday day = Weekday.Monday;
 if (day == Weekday.Tuesday)
 Console.WriteLine("Time sure flies by when you program in C#!");
If no explicit values are assigned to the enumerated items as the example above, the first element has the value 0, and the successive values are assigned to each subsequent element. However, specific values from the underlying integral type can be assigned to any of the enumerated elements (note that the variable must be type cast in order to access the base type):
 enum Age { Infant = 0, Teenager = 13, Adult = 18 };
 Age myAge = Age.Teenager;
 Console.WriteLine("You become a teenager at an age of {0}.", (int)myAge);
The underlying values of enumerated elements may go unused when the purpose of an enumeration is simply to group a set of items together, e.g., to represent a nation, state, or geographical territory in a more meaningful way than an integer could. Rather than define a group of logically related constants, it is often more readable to use an enumeration.
It may be desirable to create an enumeration with a base type other than . To do so, specify any integral type besides as with base class "extension" syntax after the name of the enumeration, as follows:
 enum CardSuit : byte { Hearts, Diamonds, Spades, Clubs };
The enumeration type is also helpful, if you need to output the value. By calling the method on the enumeration, will output the enumerations name (e.g. will output "Hearts").
Structs.
Structures (keyword ) are light-weight objects. They are mostly used when only a data container is required for a collection of value type variables. "Structs" are similar to "classes" in that they can have constructors, methods, and even implement interfaces, but there are important differences.
A can, for example, be declared like this:
 struct Person
 public string name;
 public System.DateTime birthDate;
 public int heightInCm;
 public int weightInKg;
The "struct" can then be used like this:
 Person dana = new Person();
 dana.name = "Dana Developer";
 dana.birthDate = new DateTime(1974, 7, 18);
 dana.heightInCm = 178;
 dana.weightInKg = 50;
 if (dana.birthDate &lt; DateTime.Now)
 Console.WriteLine("Thank goodness! Dana Developer isn't from the future!");
It is also possible to provide "constructors" to s to make it easier to initialize them:
 using System;
 struct Person
 string name;
 DateTime birthDate;
 int heightInCm;
 int weightInKg;
 public Person(string name, DateTime birthDate, int heightInCm, int weightInKg)
 this.name = name;
 this.birthDate = birthDate;
 this.heightInCm = heightInCm;
 this.weightInKg = weightInKg;
 public class StructWikiBookSample
 public static void Main()
 Person dana = new Person("Dana Developer", new DateTime(1974, 7, 18), 178, 50);
There is also an alternative syntax for initializing structs:
struct Person
 public string Name;
 public int Height;
 public string Occupation;
public class StructWikiBookSample2
 public static void Main()
 Person john = new Person { Name = "John", Height = 182, Occupation = "Programmer" };
"Structs" are really only used for performance reasons or, if you intend to reference it by value. Structs work best when holding a total equal to or less than 16 bytes of data. If in doubt, use classes.
Arrays.
Arrays represent a set of items all belonging to the same type. The declaration itself may use a variable or a constant to define the length of the array. However, an array has a set length and it cannot be changed after declaration.
// an array whose length is defined with a constant
int[] integers = new int[20];
int length = 0;
System.Console.Write("How long should the array be? ");
length = int.Parse(System.Console.ReadLine());
// an array whose length is defined with a variable
// this array still can't change length after declaration
double[] doubles = new double[length];