Posted By

rtipton on 05/25/09


Tagged

arrays csharp


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

paelgr
umang_nine
vali29
fyreflyX
khouser


Array in C#


 / Published in: C#
 

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace ArraysInCSharp
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. SingleDim();
  11. Console.WriteLine("++++++++++++++++++");
  12. MultiDim();
  13. }
  14.  
  15. static void SingleDim()
  16. {
  17. string[] strCities = new string[4] { "Houston", "Austin", "Tuscon", "Sedona" };
  18.  
  19. foreach (string str in strCities)
  20. {
  21. Console.WriteLine(str);
  22. }
  23. }
  24.  
  25. static void MultiDim()
  26. {
  27. string[,] strCityStates = new string[,]
  28. { { "Houston", "TX" }, { "Austin", "TX" }, { "Tuscon", "AZ" }, { "Sedona", "AZ" } };
  29.  
  30. Console.WriteLine(strCityStates[0,0] + "," + strCityStates[0,1]);
  31. Console.WriteLine(strCityStates[1,0] + "," + strCityStates[1,1]);
  32. Console.WriteLine(strCityStates[2,0] + "," + strCityStates[2,1]);
  33. Console.WriteLine(strCityStates[3,0] + "," + strCityStates[3,1]);
  34. Console.WriteLine(" ");
  35.  
  36. foreach (string str in strCityStates)
  37. {
  38. Console.WriteLine(str);
  39. }
  40. }
  41. }
  42. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tartar9 on May 25, 2009

Does

foreach(string[] str in strCityStates) { Console.WriteLin(str[0] + "," + str[1]); }

work?

I would think it would, but I don't do C#...

You need to login to post a comment.