A Review of the Array Class
A Review of the Array Class
A Class to Manage Arrays
Introduction
To assist with the use and management of arrays, you can combine the array features of the C# language and support from the .NET Framework. As mentioned already, to support arrays, the .NET Framework provides the Array class that is defined in the System namespace of the mscorlib.dll assembly.
When you create an array in C# code, whether an array of primitive values or an array of objects, you are in fact declaring a variable of type Array. Based on this, since an array variable is an object of a class type, you can use the characteristics of the Array class to create an array and/or to manipulate the values stored in the variable. You can create an array using any of the techniques we saw in the previous lessons, or you can use the Array class.
Practical Learning: Introducing Arrays and Classes
namespace CountriesStatistics2 { interface IAbbreviated { string Abbreviation { get; set; } } }
namespace CountriesStatistics2 { interface IGovernmentEntity { string Name { get; set; } int Area { get; } string Capital { get; set; } } }
namespace CountriesStatistics2
{
public class Region
{
public string Designation { get; set; }
public string Description { get; set; }
}
}
namespace CountriesStatistics2 { public class State : IGovernmentEntity, IAbbreviated { // From the IAbbreviated interface public string Abbreviation { get; set; } // From the IGovernmentEntity interface public string Name { get; set; } public int Area { get; set; } public string Capital { get; set; } // New Properties public string StateName => Name; public int AreaSqrMiles => Area; public int AreaSqrKms { get; set; } public Region Region { get; set; } public override bool Equals(object obj) { State stt = (State)obj; if (stt.Name == Name) return true; return false; } public override int GetHashCode() { return base.GetHashCode(); } } }
namespace CountriesStatistics2 { public class Federation : State { public string AdmissionUnionDate { get; set; } public int AdmissionUnionOrder { get; set; } } }
Creating an Array
To assist you with creating an array, the Array class is equipped with a method named CreateInstance() that comes in various versions. To create a one-dimensional array whose members are zero-based, you can use the following version:
public static Array CreateInstance(Type elementType, int length);
The first argument is used to specify the type of array you want to create. You are allowed to create an array of any type, that is, an array of primitive values or an array of objects. The first argument is declared as Type. This means that it can be anything. For this reason, you can use the typeof operator to cast your type. Therefore, pass the type or the class in the parentheses of the typeof operator.
The second argument specifies the number of members of the array. Using the Array class, you can create an array as follows:
Array numbers = Array.CreateInstance(typeof(double), length);
You can also use the var or the dynamic keyword to declare the variable. Here is an example:
var numbers = Array.CreateInstance(typeof(double), 5);
Practical Learning: Creating an Array
using System; namespace CountriesStatistics2 { public class UnitedStates { public Array States; public Array Regions; public UnitedStates() { Regions = Array.CreateInstance(typeof(Region), 9); States = Array.CreateInstance(typeof(Federation), 30); } } }
The Length of an Array
We know that if you declare a variable for an array but don't initialize it, you must specify the number of elements of the array. Here is an example:
public class Exercise
{
public static void Main()
{
double[] numbers = new double[5];
}
}
If you use the Array class to create an array, you must pass this constant integer as the second argument of the CreateInstance() method from the the above version. Here is an example:
using System;
public class Exercise
{
public static void Main()
{
var numbers = Array.CreateInstance(typeof(double), 5);
}
}
If the array exists already, that is, if you have already created the array or you are using an array created by someone else, to find out the number of items it contains, you can access its Length property (we already know that the length of an array is the number of elements it contains).
As an alternative, you can call the Array.GetLength() method. Its syntax is:
public int GetLength(int dimension);
For a one-dimensional array, you must pass the argument as 0. This method returns an integer that represents the number of items in the array.
The Rank of an Array
We have seen that the square brackets are used to specify that you are declaring an array. If you are creating a one-dimensional array, we saw that you could type a number in the square bracket. If you are creating a two-dimensional array, you type two numbers separated by a comma in the second pair of square brackets. Each number, whether it is one, two, or more is a placeholder for what is referred to as a dimension. In other words, a one dimensional array has a dimension of one. A two-dimensional array has a dimension of 2, and so on.
To find out the dimension of an array, the Array class provides the Rank property. Therefore, to know the dimension of an existing array, you can access its Rank property.
Fundamental Operations on an Array
Adding a Value to an Array
We know that, to initialize an array, you can open the curly brackets and list its members separated by commas, or you could access each member and assign it the desired value. To support the ability to add members to an array, the Array class is equipped with a method named SetValue that comes in different versions. To add a new item to the types of arrays we have used so far, you can call the following version of the Array.SetValue() method:
public void SetValue(object value, int index);
The first argument is the value to add to the list. The second argument is the index of the member to be added. The first item has index 1; the second item has index 2, and so on. If the array is a list of primitive values, simply pass the value for the first argument. Here are examples of calling the method:
using System;
public class Exercise
{
public static void Main()
{
Array numbers = Array.CreateInstance(typeof(double), 5);
numbers.SetValue(7628.937, 0);
numbers.SetValue(6.48, 1);
numbers.SetValue(574.9, 2);
numbers.SetValue(293749.064, 3);
numbers.SetValue(0.70257, 4);
}
}
If the array is a list of objects, use any technique to create an object and pass it as the first argument.
We indicated that whenever you create an array, you are in fact declaring an instance of the Array class. Therefore, even if you create an array using the square bracket formula, you can still call the SetValue() method to specify any member of the array. Here is an example:
public class Exercise { public static void Main() { var numbers = new double[5]; numbers.SetValue(7628.937, 0); numbers.SetValue(6.48, 1); numbers.SetValue(574.9, 2); numbers.SetValue(293749.064, 3); numbers.SetValue(0.70257, 4); } }
The Array class provides a SetValue() version for each corresponding CreateInstance() method we reviewed earlier.
Practical Learning: Adding Objects to an Array
using System;
namespace CountriesStatistics2
{
public class UnitedStates
{
public Array States;
public Array Regions;
public UnitedStates()
{
Regions = Array.CreateInstance(typeof(Region), 9);
States = Array.CreateInstance(typeof(Federation), 30);
Region reg = new Region();
reg.Designation = "East North Central";
reg.Description = "The East North Central region includes the states around the Great Lakes.";
Regions.SetValue(reg, 0);
reg = new Region()
{
Designation = "East South Central",
Description = "The East South Central portion is one of the regions designated as the South."
};
Regions.SetValue(reg, 1);
reg = new Region() { Designation = "New England", Description = "New England is the group of states in the North-East region. It is delimited in the North and North-East by Canada, in the East by the Atlantic Ocean, and in the South and West by the New York state." };
Regions.SetValue(reg, 2);
Regions.SetValue(new Region() { Designation = "Mid-Atlantic", Description = "Mid-Atlantic is a region situated in the south of New England. Mid-Atlantic is one of the regions defined by the Census bureau for statistical purposes." }, 3);
Regions.SetValue(new Region() { Designation = "Mountain", Description = "Like the name suggests, the Mountain region covers states known for their mountaneous characteristics. They are also covered by desertic areas." }, 4);
Regions.SetValue(new Region() { Designation = "Pacific", Description = "The Pacific region covers the costal western states plus the two non-continental states of Alaska and the Hawaiian islands. All states in this region have a coast on the Pacific Ocean." }, 5);
Regions.SetValue(new Region() { Designation = "South Atlantic", Description = "The South Atlantic region includes the states in the South-East part but also counts the Disctrict of Columbia." }, 6);
Regions.SetValue(new Region() { Designation = "West North Central", Description = "The West North Central region includes the states in the Great Planes area. This reqion is divided from the East North Central part by the Mississippi River. This region is characterized by vast agricultural farms and high employment." }, 7);
Regions.SetValue(new Region() { Designation = "West South Central", Description = "The West South Central part is one of the regions with (only) four states. The imposing Texas state is both the largest and the most populous state in the region." }, 8);
}
}
}
Getting a Value from an Array
To support the ability to retrieve the value of a member of an array, the Array class is equipped with a method named GetValue that is overloaded with a version corresponding to each version of the CreateInstance() and the SetValue() methods. For example, to access the values stored in a one-dimensional array, you can call this version:
public object GetValue(int index);
The index argument is the zero-based index of the member whose value you want to access. If the array is a list of primitive values, the Array.GetValue() method directly produces the value stored in the indicated position. Here is an example:
using static System.Console;
public class Exercise
{
public static void Main()
{
var numbers = new double[5];
numbers.SetValue(7628.937, 0);
numbers.SetValue(6.48, 1);
numbers.SetValue(574.9, 2);
numbers.SetValue(293749.064, 3);
numbers.SetValue(0.70257, 4);
WriteLine("Number: " + numbers.GetValue(0));
WriteLine("=================================");
}
}
This would produce:
Number: 7628.937 ================================= Press any key to continue . . .
When calling the Array.GetValue() method, if you pass an invalid value, the compiler would throw an IndexOutOfRangeException exception.
Notice that the Array.GetValue() returns an anonymous object. This means that it can return anything. Therefore, if the array you are using is a list of objects, you must cast the returned object to the appropriate class.
When calling the Array.GetValue() method, if you pass an invalid value, the webpage would throw an exception.
Practical Learning: Getting the Objects of an Arrray
using System;
namespace CountriesStatistics2
{
public class UnitedStates
{
public Array States;
public Array Regions;
public UnitedStates()
{
Regions = Array.CreateInstance(typeof(Region), 9);
States = Array.CreateInstance(typeof(Federation), 30);
Region reg = new Region();
reg.Designation = "East North Central";
reg.Description = "The East North Central region includes the states around the Great Lakes.";
Regions.SetValue(reg, 0);
reg = new Region()
{
Designation = "East South Central",
Description = "The East South Central portion is one of the regions designated as the South."
};
Regions.SetValue(reg, 1);
reg = new Region() { Designation = "New England", Description = "New England is the group of states in the North-East region. It is delimited in the North and North-East by Canada, in the East by the Atlantic Ocean, and in the South and West by the New York state." };
Regions.SetValue(reg, 2);
Regions.SetValue(new Region() { Designation = "Mid-Atlantic", Description = "Mid-Atlantic is a region situated in the south of New England. Mid-Atlantic is one of the regions defined by the Census bureau for statistical purposes." }, 3);
Regions.SetValue(new Region() { Designation = "Mountain", Description = "Like the name suggests, the Mountain region covers states known for their mountaneous characteristics. They are also covered by desertic areas." }, 4);
Regions.SetValue(new Region() { Designation = "Pacific", Description = "The Pacific region covers the costal western states plus the two non-continental states of Alaska and the Hawaiian islands. All states in this region have a coast on the Pacific Ocean." }, 5);
Regions.SetValue(new Region() { Designation = "South Atlantic", Description = "The South Atlantic region includes the states in the South-East part but also counts the Disctrict of Columbia." }, 6);
Regions.SetValue(new Region() { Designation = "West North Central", Description = "The West North Central region includes the states in the Great Planes area. This reqion is divided from the East North Central part by the Mississippi River. This region is characterized by vast agricultural farms and high employment." }, 7);
Regions.SetValue(new Region() { Designation = "West South Central", Description = "The West South Central part is one of the regions with (only) four states. The imposing Texas state is both the largest and the most populous state in the region." }, 8);
States.SetValue(new Federation() { Abbreviation = "RI", Name = "Rhode Island", Area = 1545, AreaSqrKms = 4002, AdmissionUnionDate = "05/29/1790", AdmissionUnionOrder = 13, Capital = "Providence", Region = (Region)(Regions.GetValue(2)) }, 0);
States.SetValue(new Federation() { Abbreviation = "OH", Name = "Ohio", Area = 44828, AreaSqrKms = 116103, AdmissionUnionDate = "03/01/1803", AdmissionUnionOrder = 17, Capital = "Columbus", Region = (Region)(Regions.GetValue(0)) }, 1);
States.SetValue(new Federation() { Abbreviation = "KY", Name = "Kentucky", Area = 40411, AreaSqrKms = 104665, AdmissionUnionDate = "06/01/1792", AdmissionUnionOrder = 15, Capital = "Frankfort", Region = (Region)(Regions.GetValue(1)) }, 2);
States.SetValue(new Federation() { Abbreviation = "IA", Name = "Iowa", Area = 56276, AreaSqrKms = 145754, AdmissionUnionDate = "12/28/1846", AdmissionUnionOrder = 29, Capital = "Des Moines", Region = (Region)(Regions.GetValue(7)) }, 3);
States.SetValue(new Federation() { Abbreviation = "WI", Name = "Wisconsin", Area = 65503, AreaSqrKms = 169653, AdmissionUnionDate = "05/29/1848", AdmissionUnionOrder = 30, Capital = "Madison", Region = (Region)(Regions.GetValue(0)) }, 4);
States.SetValue(new Federation() { Abbreviation = "VT", Name = "Vermont", Area = 9615, AreaSqrKms = 24903, AdmissionUnionDate = "03/04/1791", AdmissionUnionOrder = 14, Capital = "Montpelier", Region = (Region)(Regions.GetValue(2)) }, 5);
States.SetValue(new Federation() { Abbreviation = "ID", Name = "Idaho", Area = 83574, AreaSqrKms = 216456, AdmissionUnionDate = "07/03/1890", AdmissionUnionOrder = 43, Capital = "Boise", Region = (Region)(Regions.GetValue(4)) }, 6);
States.SetValue(new Federation() { Abbreviation = "ME", Name = "Maine", Area = 35387, AreaSqrKms = 91653, AdmissionUnionDate = "03/15/1820", AdmissionUnionOrder = 23, Capital = "Augusta", Region = (Region)(Regions.GetValue(2)) }, 7);
States.SetValue(new Federation() { Abbreviation = "OR", Name = "Oregon", Area = 98386, AreaSqrKms = 254819, AdmissionUnionDate = "02/14/1859", AdmissionUnionOrder = 33, Capital = "Salem", Region = (Region)(Regions.GetValue(5)) }, 8);
States.SetValue(new Federation() { Abbreviation = "ND", Name = "North Dakota", Area = 70704, AreaSqrKms = 183123, AdmissionUnionDate = "11/02/1889", AdmissionUnionOrder = 39, Capital = "Bismarck", Region = (Region)(Regions.GetValue(7)) }, 9);
States.SetValue(new Federation() { Abbreviation = "IN", Name = "Indiana", Area = 36420, AreaSqrKms = 94328, AdmissionUnionDate = "12/11/1816", AdmissionUnionOrder = 19, Capital = "Indianapolis", Region = (Region)(Regions.GetValue(0)) }, 10);
States.SetValue(new Federation() { Abbreviation = "MS", Name = "Mississippi", Area = 48434, AreaSqrKms = 125443, AdmissionUnionDate = "12/10/1817", AdmissionUnionOrder = 20, Capital = "Jackson", Region = (Region)(Regions.GetValue(1)) }, 11);
States.SetValue(new Federation() { Abbreviation = "TX", Name = "Texas", Area = 268601, AreaSqrKms = 695676, AdmissionUnionDate = "12/29/1845", AdmissionUnionOrder = 28, Capital = "Austin", Region = (Region)(Regions.GetValue(8)) }, 12);
States.SetValue(new Federation() { Abbreviation = "MT", Name = "Montana", Area = 147046, AreaSqrKms = 380850, AdmissionUnionDate = "11/08/1889", AdmissionUnionOrder = 41, Capital = "Helena", Region = (Region)(Regions.GetValue(4)) }, 13);
States.SetValue(new Federation() { Abbreviation = "NC", Name = "North Carolina", Area = 53821, AreaSqrKms = 139397, AdmissionUnionDate = "11/21/1789", AdmissionUnionOrder = 12, Capital = "Raleigh", Region = (Region)(Regions.GetValue(6)) }, 14);
States.SetValue(new Federation() { Abbreviation = "TN", Name = "Tennessee", Area = 42146, AreaSqrKms = 109158, AdmissionUnionDate = "06/01/1796", AdmissionUnionOrder = 16, Capital = "Nashville", Region = (Region)(Regions.GetValue(1)) }, 15);
States.SetValue(new Federation() { Abbreviation = "NE", Name = "Nebraska", Area = 77358, AreaSqrKms = 200358, AdmissionUnionDate = "03/01/1867", AdmissionUnionOrder = 37, Capital = "Lincoln", Region = (Region)(Regions.GetValue(7)) }, 16);
States.SetValue(new Federation() { Abbreviation = "IL", Name = "Illinois", Area = 57918, AreaSqrKms = 150007, AdmissionUnionDate = "12/03/1818", AdmissionUnionOrder = 21, Capital = "Springfield", Region = (Region)(Regions.GetValue(0)) }, 17);
States.SetValue(new Federation() { Abbreviation = "KS", Name = "Kansas", Area = 82282, AreaSqrKms = 213110, AdmissionUnionDate = "01/29/1861", AdmissionUnionOrder = 34, Capital = "Topeka", Region = (Region)(Regions.GetValue(7)) }, 18);
States.SetValue(new Federation() { Abbreviation = "NH", Name = "New Hampshire", Area = 9351, AreaSqrKms = 24219, AdmissionUnionDate = "06/21/1788", AdmissionUnionOrder = 9, Capital = "Concord", Region = (Region)(Regions.GetValue(2)) }, 19);
States.SetValue(new Federation() { Abbreviation = "DE", Name = "Delaware", Area = 2489, AreaSqrKms = 6447, AdmissionUnionDate = "12/07/1787", AdmissionUnionOrder = 1, Capital = "Dover", Region = (Region)(Regions.GetValue(6)) }, 20);
States.SetValue(new Federation() { Abbreviation = "NJ", Name = "New Jersey", Area = 8722, AreaSqrKms = 22590, AdmissionUnionDate = "12/18/1787", AdmissionUnionOrder = 3, Capital = "Trenton", Region = (Region)(Regions.GetValue(3)) }, 21);
States.SetValue(new Federation() { Abbreviation = "AK", Name = "Alaska", Area = 656424, AreaSqrKms = 1700139, AdmissionUnionDate = "01/03/1959", AdmissionUnionOrder = 49, Capital = "Juneau", Region = (Region)(Regions.GetValue(5)) }, 22);
States.SetValue(new Federation() { Abbreviation = "NM", Name = "New Mexico", Area = 121598, AreaSqrKms = 314939, AdmissionUnionDate = "01/06/1912", AdmissionUnionOrder = 47, Capital = "Santa Fe", Region = (Region)(Regions.GetValue(4)) }, 23);
States.SetValue(new Federation() { Abbreviation = "NY", Name = "New York", Area = 54475, AreaSqrKms = 141089, AdmissionUnionDate = "07/26/1788", AdmissionUnionOrder = 11, Capital = "Albany", Region = (Region)(Regions.GetValue(3)) }, 24);
States.SetValue(new Federation() { Abbreviation = "CA", Name = "California", Area = 163707, AreaSqrKms = 424002, AdmissionUnionDate = "09/09/1850", AdmissionUnionOrder = 31, Capital = "Sacramento", Region = (Region)(Regions.GetValue(5)) }, 25);
States.SetValue(new Federation() { Abbreviation = "MO", Name = "Missouri", Area = 69709, AreaSqrKms = 180546, AdmissionUnionDate = "08/10/01821", AdmissionUnionOrder = 24, Capital = "Jefferson City", Region = (Region)(Regions.GetValue(7)) }, 26);
States.SetValue(new Federation() { Abbreviation = "OK", Name = "Oklahoma", Area = 69903, AreaSqrKms = 181049, AdmissionUnionDate = "11/16/1907", AdmissionUnionOrder = 46, Capital = "Oklahoma City", Region = (Region)(Regions.GetValue(8)) }, 27);
States.SetValue(new Federation() { Abbreviation = "PA", Name = "Pennsylvania", Area = 46058, AreaSqrKms = 119291, AdmissionUnionDate = "12/12/1787", AdmissionUnionOrder = 2, Capital = "Harrisburg", Region = (Region)(Regions.GetValue(3)) }, 28);
States.SetValue(new Federation() { Abbreviation = "SC", Name = "South Carolina", Area = 32007, AreaSqrKms = 82898, AdmissionUnionDate = "05/23/1788", AdmissionUnionOrder = 8, Capital = "Columbia", Region = (Region)(Regions.GetValue(6)) }, 29);
}
}
}
Looping for an Array
To access one member of the array at a time, you can use a loop to access any member using its index. You can use any of the classic three loops: for, while, or do...while. Here is an example that uses a for loop and the Length property to know the number of members of an array:
using static System.Console; public class Exercise { public static void Main() { var numbers = new double[5]; numbers.SetValue(7628.937, 0); numbers.SetValue(6.48, 1); numbers.SetValue(574.9, 2); numbers.SetValue(293749.064, 3); numbers.SetValue(0.70257, 4); for (int i = 0; i < numbers.Length; i++) WriteLine("Number: " + numbers.GetValue(i)); WriteLine("================================="); } }
This would produce:
Number: 7628.937 Number: 6.48 Number: 574.9 Number: 293749.064 Number: 0.70257 ================================= Press any key to continue . . .
Practical Learning: Looping Through an Arrray of Objects
using System; namespace CountriesStatistics2 { public class CountriesStatistics { public static void Main(string[] args) { Array states = Array.CreateInstance(typeof(Federation), 30); Array regions = Array.CreateInstance(typeof(Region), 9); regions.SetValue(new Region() { Designation = "East North Central", Description = "The East North Central region includes the states around the Great Lakes." }, 0); regions.SetValue(new Region() { Designation = "East South Central", Description = "The East South Central portion is one of the regions designated as the South." }, 1); regions.SetValue(new Region() { Designation = "New England", Description = "New England is the group of states in the North-East region. It is delimited in the North and North-East by Canada, in the East by the Atlantic Ocean, and in the South and West by the New York state." }, 2); regions.SetValue(new Region() { Designation = "Mid-Atlantic", Description = "Mid-Atlantic is a region situated in the south of New England. Mid-Atlantic is one of the regions defined by the Census bureau for statistical purposes." }, 3); regions.SetValue(new Region() { Designation = "Mountain", Description = "Like the name suggests, the Mountain region covers states known for their mountaneous characteristics. They are also covered by desertic areas." }, 4); regions.SetValue(new Region() { Designation = "Pacific", Description = "The Pacific region covers the costal western states plus the two non-continental states of Alaska and the Hawaiian islands. All states in this region have a coast on the Pacific Ocean." }, 5); regions.SetValue(new Region() { Designation = "South Atlantic", Description = "The South Atlantic region includes the states in the South-East part but also counts the Disctrict of Columbia." }, 6); regions.SetValue(new Region() { Designation = "West North Central", Description = "The West North Central region includes the states in the Great Planes area. This reqion is divided from the East North Central part by the Mississippi River. This region is characterized by vast agricultural farms and high employment." }, 7); regions.SetValue(new Region() { Designation = "West South Central", Description = "The West South Central part is one of the regions with (only) four states. The imposing Texas state is both the largest and the most populous state in the region." }, 8); states.SetValue(new Federation() { Abbreviation = "RI", Name = "Rhode Island ", Area = 1545, AreaSqrKms = 4002, AdmissionUnionDate = "05/29/1790", AdmissionUnionOrder = 13, Capital = "Providence ", Region = (Region)(regions.GetValue(2)) }, 0); states.SetValue(new Federation() { Abbreviation = "OH", Name = "Ohio ", Area = 44828, AreaSqrKms = 116103, AdmissionUnionDate = "03/01/1803", AdmissionUnionOrder = 17, Capital = "Columbus ", Region = (Region)(regions.GetValue(0)) }, 1); states.SetValue(new Federation() { Abbreviation = "KY", Name = "Kentucky ", Area = 40411, AreaSqrKms = 104665, AdmissionUnionDate = "06/01/1792", AdmissionUnionOrder = 15, Capital = "Frankfort ", Region = (Region)(regions.GetValue(1)) }, 2); states.SetValue(new Federation() { Abbreviation = "IA", Name = "Iowa ", Area = 56276, AreaSqrKms = 145754, AdmissionUnionDate = "12/28/1846", AdmissionUnionOrder = 29, Capital = "Des Moines ", Region = (Region)(regions.GetValue(7)) }, 3); states.SetValue(new Federation() { Abbreviation = "WI", Name = "Wisconsin ", Area = 65503, AreaSqrKms = 169653, AdmissionUnionDate = "05/29/1848", AdmissionUnionOrder = 30, Capital = "Madison ", Region = (Region)(regions.GetValue(0)) }, 4); states.SetValue(new Federation() { Abbreviation = "VT", Name = "Vermont ", Area = 9615, AreaSqrKms = 24903, AdmissionUnionDate = "03/04/1791", AdmissionUnionOrder = 14, Capital = "Montpelier ", Region = (Region)(regions.GetValue(2)) }, 5); states.SetValue(new Federation() { Abbreviation = "ID", Name = "Idaho ", Area = 83574, AreaSqrKms = 216456, AdmissionUnionDate = "07/03/1890", AdmissionUnionOrder = 43, Capital = "Boise ", Region = (Region)(regions.GetValue(4)) }, 6); states.SetValue(new Federation() { Abbreviation = "ME", Name = "Maine ", Area = 35387, AreaSqrKms = 91653, AdmissionUnionDate = "03/15/1820", AdmissionUnionOrder = 23, Capital = "Augusta ", Region = (Region)(regions.GetValue(2)) }, 7); states.SetValue(new Federation() { Abbreviation = "OR", Name = "Oregon ", Area = 98386, AreaSqrKms = 254819, AdmissionUnionDate = "02/14/1859", AdmissionUnionOrder = 33, Capital = "Salem ", Region = (Region)(regions.GetValue(5)) }, 8); states.SetValue(new Federation() { Abbreviation = "ND", Name = "North Dakota ", Area = 70704, AreaSqrKms = 183123, AdmissionUnionDate = "11/02/1889", AdmissionUnionOrder = 39, Capital = "Bismarck ", Region = (Region)(regions.GetValue(7)) }, 9); states.SetValue(new Federation() { Abbreviation = "IN", Name = "Indiana ", Area = 36420, AreaSqrKms = 94328, AdmissionUnionDate = "12/11/1816", AdmissionUnionOrder = 19, Capital = "Indianapolis ", Region = (Region)(regions.GetValue(0)) }, 10); states.SetValue(new Federation() { Abbreviation = "MS", Name = "Mississippi ", Area = 48434, AreaSqrKms = 125443, AdmissionUnionDate = "12/10/1817", AdmissionUnionOrder = 20, Capital = "Jackson ", Region = (Region)(regions.GetValue(1)) }, 11); states.SetValue(new Federation() { Abbreviation = "TX", Name = "Texas ", Area = 268601, AreaSqrKms = 695676, AdmissionUnionDate = "12/29/1845", AdmissionUnionOrder = 28, Capital = "Austin ", Region = (Region)(regions.GetValue(8)) }, 12); states.SetValue(new Federation() { Abbreviation = "MT", Name = "Montana ", Area = 147046, AreaSqrKms = 380850, AdmissionUnionDate = "11/08/1889", AdmissionUnionOrder = 41, Capital = "Helena ", Region = (Region)(regions.GetValue(4)) }, 13); states.SetValue(new Federation() { Abbreviation = "NC", Name = "North Carolina", Area = 53821, AreaSqrKms = 139397, AdmissionUnionDate = "11/21/1789", AdmissionUnionOrder = 12, Capital = "Raleigh ", Region = (Region)(regions.GetValue(6)) }, 14); states.SetValue(new Federation() { Abbreviation = "TN", Name = "Tennessee ", Area = 42146, AreaSqrKms = 109158, AdmissionUnionDate = "06/01/1796", AdmissionUnionOrder = 16, Capital = "Nashville ", Region = (Region)(regions.GetValue(1)) }, 15); states.SetValue(new Federation() { Abbreviation = "NE", Name = "Nebraska ", Area = 77358, AreaSqrKms = 200358, AdmissionUnionDate = "03/01/1867", AdmissionUnionOrder = 37, Capital = "Lincoln ", Region = (Region)(regions.GetValue(7)) }, 16); states.SetValue(new Federation() { Abbreviation = "IL", Name = "Illinois ", Area = 57918, AreaSqrKms = 150007, AdmissionUnionDate = "12/03/1818", AdmissionUnionOrder = 21, Capital = "Springfield ", Region = (Region)(regions.GetValue(0)) }, 17); states.SetValue(new Federation() { Abbreviation = "KS", Name = "Kansas ", Area = 82282, AreaSqrKms = 213110, AdmissionUnionDate = "01/29/1861", AdmissionUnionOrder = 34, Capital = "Topeka ", Region = (Region)(regions.GetValue(7)) }, 18); states.SetValue(new Federation() { Abbreviation = "NH", Name = "New Hampshire ", Area = 9351, AreaSqrKms = 24219, AdmissionUnionDate = "06/21/1788", AdmissionUnionOrder = 9, Capital = "Concord ", Region = (Region)(regions.GetValue(2)) }, 19); states.SetValue(new Federation() { Abbreviation = "DE", Name = "Delaware ", Area = 2489, AreaSqrKms = 6447, AdmissionUnionDate = "12/07/1787", AdmissionUnionOrder = 1, Capital = "Dover ", Region = (Region)(regions.GetValue(6)) }, 20); states.SetValue(new Federation() { Abbreviation = "NJ", Name = "New Jersey ", Area = 8722, AreaSqrKms = 22590, AdmissionUnionDate = "12/18/1787", AdmissionUnionOrder = 3, Capital = "Trenton ", Region = (Region)(regions.GetValue(3)) }, 21); states.SetValue(new Federation() { Abbreviation = "AK", Name = "Alaska ", Area = 656424, AreaSqrKms = 1700139, AdmissionUnionDate = "01/03/1959", AdmissionUnionOrder = 49, Capital = "Juneau ", Region = (Region)(regions.GetValue(5)) }, 22); states.SetValue(new Federation() { Abbreviation = "NM", Name = "New Mexico ", Area = 121598, AreaSqrKms = 314939, AdmissionUnionDate = "01/06/1912", AdmissionUnionOrder = 47, Capital = "Santa Fe ", Region = (Region)(regions.GetValue(4)) }, 23); states.SetValue(new Federation() { Abbreviation = "NY", Name = "New York ", Area = 54475, AreaSqrKms = 141089, AdmissionUnionDate = "07/26/1788", AdmissionUnionOrder = 11, Capital = "Albany ", Region = (Region)(regions.GetValue(3)) }, 24); states.SetValue(new Federation() { Abbreviation = "CA", Name = "California ", Area = 163707, AreaSqrKms = 424002, AdmissionUnionDate = "09/09/1850", AdmissionUnionOrder = 31, Capital = "Sacramento ", Region = (Region)(regions.GetValue(5)) }, 25); states.SetValue(new Federation() { Abbreviation = "MO", Name = "Missouri ", Area = 69709, AreaSqrKms = 180546, AdmissionUnionDate = "08/10/1821", AdmissionUnionOrder = 24, Capital = "Jefferson City", Region = (Region)(regions.GetValue(7)) }, 26); states.SetValue(new Federation() { Abbreviation = "OK", Name = "Oklahoma ", Area = 69903, AreaSqrKms = 181049, AdmissionUnionDate = "11/16/1907", AdmissionUnionOrder = 46, Capital = "Oklahoma City ", Region = (Region)(regions.GetValue(8)) }, 27); states.SetValue(new Federation() { Abbreviation = "PA", Name = "Pennsylvania ", Area = 46058, AreaSqrKms = 119291, AdmissionUnionDate = "12/12/1787", AdmissionUnionOrder = 2, Capital = "Harrisburg ", Region = (Region)(regions.GetValue(3)) }, 28); states.SetValue(new Federation() { Abbreviation = "SC", Name = "South Carolina", Area = 32007, AreaSqrKms = 82898, AdmissionUnionDate = "05/23/1788", AdmissionUnionOrder = 8, Capital = "Columbia ", Region = (Region)(regions.GetValue(6)) }, 29); Console.WriteLine(" Area Admission to Union"); Console.WriteLine(" # Abbrv State Name SqrMls Km2 Date Order Capital Region"); Console.WriteLine("----------------------------------------------------------------------------------------------------"); for (int counter = 0; counter <= states.Length - 1; counter++) { Federation stt = (Federation)states.GetValue(counter); Console.WriteLine("{0,2} {1,2} {2} {3,6} {4,7} {5,8} {6,5} {7} {8}", counter + 1, stt.Abbreviation, stt.StateName, stt.AreaSqrMiles, stt.AreaSqrKms, stt.AdmissionUnionDate, stt.AdmissionUnionOrder, stt.Capital, stt.Region.Designation); } Console.WriteLine("===================================================================================================="); } } }
Area Admission to Union # Abbrv State Name SqrMls Km2 Date Order Capital Region ---------------------------------------------------------------------------------------------------- 1 RI Rhode Island 1545 4002 05/29/1790 13 Providence New England 2 OH Ohio 44828 116103 03/01/1803 17 Columbus East North Central 3 KY Kentucky 40411 104665 06/01/1792 15 Frankfort East South Central 4 IA Iowa 56276 145754 12/28/1846 29 Des Moines West North Central 5 WI Wisconsin 65503 169653 05/29/1848 30 Madison East North Central 6 VT Vermont 9615 24903 03/04/1791 14 Montpelier New England 7 ID Idaho 83574 216456 07/03/1890 43 Boise Mountain 8 ME Maine 35387 91653 03/15/1820 23 Augusta New England 9 OR Oregon 98386 254819 02/14/1859 33 Salem Pacific 10 ND North Dakota 70704 183123 11/02/1889 39 Bismarck West North Central 11 IN Indiana 36420 94328 12/11/1816 19 Indianapolis East North Central 12 MS Mississippi 48434 125443 12/10/1817 20 Jackson East South Central 13 TX Texas 268601 695676 12/29/1845 28 Austin West South Central 14 MT Montana 147046 380850 11/08/1889 41 Helena Mountain 15 NC North Carolina 53821 139397 11/21/1789 12 Raleigh South Atlantic 16 TN Tennessee 42146 109158 06/01/1796 16 Nashville East South Central 17 NE Nebraska 77358 200358 03/01/1867 37 Lincoln West North Central 18 IL Illinois 57918 150007 12/03/1818 21 Springfield East North Central 19 KS Kansas 82282 213110 01/29/1861 34 Topeka West North Central 20 NH New Hampshire 9351 24219 06/21/1788 9 Concord New England 21 DE Delaware 2489 6447 12/07/1787 1 Dover South Atlantic 22 NJ New Jersey 8722 22590 12/18/1787 3 Trenton Mid-Atlantic 23 AK Alaska 656424 1700139 01/03/1959 49 Juneau Pacific 24 NM New Mexico 121598 314939 01/06/1912 47 Santa Fe Mountain 25 NY New York 54475 141089 07/26/1788 11 Albany Mid-Atlantic 26 CA California 163707 424002 09/09/1850 31 Sacramento Pacific 27 MO Missouri 69709 180546 08/10/1821 24 Jefferson City West North Central 28 OK Oklahoma 69903 181049 11/16/1907 46 Oklahoma City West South Central 29 PA Pennsylvania 46058 119291 12/12/1787 2 Harrisburg Mid-Atlantic 30 SC South Carolina 32007 82898 05/23/1788 8 Columbia South Atlantic ==================================================================================================== Press any key to continue . . .
|
||
Previous | Copyright © 2008-2019, FunctionX | Next |
|