Created
March 20, 2010 03:14
-
-
Save rtipton/338451 to your computer and use it in GitHub Desktop.
C# -- Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace ArraysInCSharp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
SingleDim(); | |
Console.WriteLine("++++++++++++++++++"); | |
MultiDim(); | |
} | |
static void SingleDim() | |
{ | |
string[] strCities = new string[4] { "Houston", "Austin", "Tuscon", "Sedona" }; | |
foreach (string str in strCities) | |
{ | |
Console.WriteLine(str); | |
} | |
} | |
static void MultiDim() | |
{ | |
string[,] strCityStates = new string[,] | |
{ { "Houston", "TX" }, { "Austin", "TX" }, { "Tuscon", "AZ" }, { "Sedona", "AZ" } }; | |
Console.WriteLine(strCityStates[0,0] + "," + strCityStates[0,1]); | |
Console.WriteLine(strCityStates[1,0] + "," + strCityStates[1,1]); | |
Console.WriteLine(strCityStates[2,0] + "," + strCityStates[2,1]); | |
Console.WriteLine(strCityStates[3,0] + "," + strCityStates[3,1]); | |
Console.WriteLine(" "); | |
foreach (string str in strCityStates) | |
{ | |
Console.WriteLine(str); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment