Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Content Obsolete

This content is no longer current. We recommend you try the following url for more up to date content: http://channel9.msdn.com/Series/C-Fundamentals-for-Absolute-Beginners

Creating Arrays of Values - 09

14 minutes, 51 seconds


Right click “Save as…”

In this lesson we talk about arrays, which are multi-part variables—a "bucket" containing other "buckets," if you will. We demonstrate how to declare and utilize arrays, including setting and retrieving their values, initializing their values, attempting to access values outside of the boundaries of the array, and iterating through arrays using the foreach statement. Finally, we demonstrate a couple of powerful built-in methods that give arrays added features.

Download the source code for Creating Arrays of Values


Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
  • I got a bit lost on a bit of this. I did some fiddling and started understanding more. I tried applying the Array.Reverse to the int array and that gave me a bit of a better understanding of how that line of code works. It's use then with the char array made more sense.

  • Also, what does the ".ToString()" get us in the "Console.WriteLine(numbers[i].ToString());" line do? I did it with just "Console.WriteLine(numbers[i]);" and it worked.

  • @Dan12R ... First, thanks for the feedback ... this helps us refine the content going forward once we see where the rough spots are.

    Second, to your question ... .ToString() ... in this SPECIFIC case, the .ToString() doesn't buy much because Console.WriteLine() can accept just about any data type you throw at it (In fact, there are 19 versions of this method ... based on what you pass into it, the correct version of that WriteLine() method will be called and the data converted appropriately for display in the Console window.

    The reason why I added a .ToString() was out of habit - a habit born out of the need in .NET explicitly convert numeric data to a string when presenting on a screen (like a web page, a windows form, etc.)

    So, the good news is that you fought through this and figured it out.  Congrats.  I'm sorry if the explanations were not quite clear enough on this one.

  • srinivassrinivas

    Hi Bob,

    Your videos are very good.but have to wait for along time for these videos to buffer.can u tell me what should be the internet speed to play these videos without taking much time to buffer and i wanted to buy these videos and my frd in us will be paying on behalf of me is it possible to access vidoes then from my system

  • @srinivas: Hi, sorry -- I'm a bit confused with your question.  The videos on channel9.msdn.com are free.  If you're referring to these videos, you should be able to download them directly from links next to the video player.  If you are referring to my personal website, www.learnvisualstudio.net -- if streaming is a problem -- we do offer the ability to download the videos to your hard drive in a .zip format.  Please see our site for more information.  Thank you for your interest!

  • baklasbaklas

    @srinivas: I have the same problem when looking at the videos, but then I found out that shutting down the Channel9 tab and finding it again from the startup tab solved the problem. I have to do this after each video, so it is a bit frustrating when I actually do have time to look at several videos in a row. Thanks for the videos btw Bob, great stuff and easy to follow!

  • @baklas: Thanks for the confirmation on that issue!  Also, thanks for the nice note.  Smiley

  • Alex WadeAlex Wade

    I am a beginner to programming and I would like to say this is a great starting point. I have crawled the web to find your gem of a great lesson plan. I would like to say thank you.

  • @Alex Wade: Thanks Alex, glad you're enjoying the series.  Best wishes!

  • Jake BJake B

    Someone's a Lost fan, eh, Bob? ;)

    But seriously, your lessons are extremely helpful, and perfectly paced in terms of how you introduce new concepts. Thanks so much for these.

  • @Jake B: Got to have a little fun with your examples otherwise life gets boring.  Smiley  Glad you're enjoying these.

  • Thennarasanthens #(: Known is a Drop, UnKnown is an Ocean :)#

    @BobTabor: Easy to understand videos, Thanks Bob Smiley

  • @BobTabor I really like your videos they are definitely helping me understand the language!

    Got a question though.

    Let's say I want C# to create an array of numbers between 1 and 50 and then print that array to my screen or just store it in memory so that I can manipulate the data in the future.

    What would be the most efficient way to do this? I could write out the array myself but what I'd really like is for C# to create the array for me.

    Alternatively, if you know of an msdn article that explains how to do this, i'd be happy to do some reading too!

  • Sudarsan MandalSudarsan Mandal

    It is a palindrome programme

    static void Main(string[] args)
    string str = "";
    Console.WriteLine("Enter a String");
    string s = Console.ReadLine();
    int i = s.Length;
    for (int j = i-1; j >= 0; j--)
    str = str + s[j];
    if (str == s)
    Console.WriteLine(s + " is palindrome");
    Console.WriteLine(s + " is not a palindeome");

    my question is 'str = str + s[j];' in this line.
    What is the meaning of 's[j]' ?
    Is it a array ?
    If it is array, how to work it ?
    Please.....Explain it...

  • Sudarsan MandalSudarsan Mandal

    here is the another program of palindrome...

    static void Main()
    char[] n;
    Console.WriteLine("Enter a string to check palindrome or not");
    string a = Console.ReadLine();

    n = a.ToCharArray();
    string n2 = new string(n);
    //string n2 = n.ToString();
    if (a == n2)
    Console.WriteLine("Is not palindrome");

    My question is
    'string n2 = new string(n);
    //string n2 = n.ToString();'
    in this two line...
    When i write 'string n2 = new string(n);' it execute properly
    but when i execute using next commented line 'string n2 = n.ToString();', it execute but not proper....why????
    please explain difference between two lines.....

    your all videos are excellent ....

  • @Sudarsan Mandal: Lower-case 's' string is a C# data type.  Upper-case 'S' String is a .NET object.  The upper-case 'S' string has access to the .ToString() method.  Hope that helps!

  • Zohaib RazaZohaibRaza Zohaib

    Hey Bob your VIDEOS are awesome.

    Just wanted to bring to the notice of the other users:




    produce two different results. I just got into it in mistake but proved to be a great learning. Thanks once again for your videos Bob.

  • @ZohaibRaza: Awesome ... always experiment ... great way to push the envelope and learn more like you just did.  Best wishes to you!

  • Clinton BilledeauxClinton Billedeaux

    I've been teaching myself C# for the last year, and while my progress is concrete enough to create a QuickBooks client for the business I work for, these videos are helping to fill in a lot of holes I didn't even realize I had. Specifically, I didn't know that Arrays were so powerful...even after a year! My boss is definitely buying me a lifetime subscription to this site.

  • @Clinton Billedeaux: Awesome.  Thanks for the nice words.  Glad this is working for you!  Big Smile

  • UliUli

    Thanks Bob for another very helpful tutorial. I have a question though when seeing that one: Are arrays only one-dimensional or can they have more dimensions too (like a matrix for example in mathematics)?

  • @Uli:  Sorry I missed this post ... you can have multi-dimensional and even sparse arrays just like in other languages.


  • BandyBandy

    Hi Bob,

    Great series for someone fresh to the world of c# and even programming as a whole such as myself!

    Is there a specific need for the 'foreach' method in this example such as a best practice? The code seems to yield the same result when I experimented and ran without it (which seems logical as it has already stored in and array and reversed it)?

  • BandyBandy

    Hi Bob,

    Great series for someone fresh to the world of c# and even programming as a whole such as myself!

    Is there a specific need for the 'foreach' method in this example such as a best practice? The code seems to yield the same result when I experimented and ran without it (which seems logical as it has already stored in and array and reversed it)?

  • @Bandy: Hi!  When working with little demo apps, it is sometimes hard to see the need for a given language element.  I'm working from memory here, but often I would use a for loop, not a foreach when working with arrays.  I would use a foreach when working with collections, and I'm sure I'll be demonstrating that later in this series.  So, for now, just be aware that there's several means of iterating through a grouping of data (like an array or collection) and later you can see better usage patterns for each.  Hope that helps!

  • I'm following the lessons and most of what I see I have seen before.  Let me qualify that statement.  Last programming I did was in College some 20 years ago and using Pascal 5.5.  With the Arrays lesson I now need to really pay attention.  My goal is to modify the Sophia Bot application which was written in 2007 by James Ashley and targeted the .Net 3.0 environment.  I am trying to use it as a voice interface for a Robot.  I am using VS 2010 and will be using the MS Speech SDK 11 because I am using the MS Kinect and there will be a lot of rules for the grammers.  The original program used the MS SAPI 5.0 TTS.  I have 2 questions: 1. Are the Arrays in C# infinite or is there a limit to the number of objects the Array can hold and is there a limit to the object size within the Array?. 2. I should have asked this at the beginning lesson but how do I determine which application to use when I start up VS 2010?  There are so many choices.  I really enjoy the lessons and you are doing a great job!!!!  Thanks for the hard work that was put into this series.

  • @smithdavidp: (1) Check this out:


    (2) I would suggest picking either the general development settings or settings specific to C#.  I know there are differences in window placement and perhaps some keyboard shortcuts.  There's not a lot of help on MSDN for this dialog (at least, that I could find).  Check this out:


    Good luck!

  • JeffJeff

    I just started learning C# for my Programming Fundamentals class and I have to say these videos are helping me so much more than long winded text books. You explain things clearly and go over them several times and what i like best is you suggest where there are hiccups that alot of coders have which shows you really know your stuff. Thanks so very much, your videos are a lifesaver. :)

  • @Jeff: Smiley Cool, thanks for writing Jeff.  Made my day.

  • i want to now about jagged array. if u can have a video tutorial please upload that    

  • JayJay

    I am having problems with "Array.Reverse" and unable to reverse the string.
    I get the following message "Error 2 The type or namespace name 'Reverse' does not exist in the namespace 'Array' (are you missing an assembly reference?)"

    This is specifically regarding your exercise at 11:17

  • @Jay: Do you have a using statement at the very top of your code?

    using System;

    That's the only scenario I can foresee where that would happen.  Also, make sure everything is spelled and capitalized exactly like I have it in my code.  Good luck!

  • ArnasArnas

    @Jay and @BobTabor: well i'm new to C#, and i'm watching videos, as fast as i can understand the situation of jay it's better allways to declare statements like BobTabor said on the issue that you Jay got:

    using System;

    But it's not in need, but it's good practice to add in top of your code for later use, but you can also use library system like that for example:


    But of course it makes more writing as BobTabor said, so better declare it at top of a file, if i'm wrong correct me :)
    And thanks for videos, because i'm learning C3 that i need in my job. It's a challenge to me :)

  • ismailismail

    hi Bob,

    Thanks for sharing your knowledge and understanding with the world!!!

  • SenCanSenCan

    Hi Bob, again many thanks for teaching V3. I noticed you saved all as you go. As we develop a program we want to keep the old ones as reminder. How can I save the corrected program as a new project?
    Thks a bunch.

  • TomTom

    Love your videos and great job at explaining. Not sure if there is anything I can do becaue I am having a hard time seeing the text on your screen so I have to download code just to follow along ??

  • anselm fowelanselm fowel

    wow. really love you work, looks like im the first Nigerian hear, thanks a lot

  • AndyAndy


    Fantastic video series! I'm picking things up much faster than I anticipated. I really appreciate them.

  • beavisbeavis

    hi thanks for all the lessons
    however you seem to be typing a bunch of statements etc....then numbers without explaining step by step what this serves purpose wise
    for example name [] then number (number) one will get lost completelty as it is not made clear where exactly when to put this i.e. can you put these sentences anywhere?

  • VimalVimal

    Great Series, i have gone through C# and HTML5 series. it saves my precious hours which i needed to spend reading books.

  • Jesus Ambrizjambriz jambriz
    Another resource for arrays is: http://msdn.microsoft.com/es-mx/library/2yd9wwz4(v=vs.80).aspx Otro recurso para generar arreglos es: http://msdn.microsoft.com/es-mx/library/2yd9wwz4(v=vs.80).aspx
  • Jesus Ambrizjambriz jambriz

    Los siguientes ejemplos son en español sobre arreglos unidimensionales y bidimensionales

    Another example using a didimensional array:


  • Jesus Ambrizjambriz jambriz

    El siguiente ejemplo de código está en español sobre arreglos unidimensionales en C#

    Example of code using a simple array:



  • Golnazgolnazal HEY HEY HEY

    opening thread

  • GedalyaGedalya

    Hi Bob, Thanks for these lessons.

    I'm having a little issue with charArray. When i run the program, each letter is displayed in its own line (vertically, not horizontally) I have Windows 8 and visual studio express 2012. This applies for regular and reverse array.

    Thanks Golnazal for opening the thread

  • Clint RutkasClint I'm a "developer"
    @Gedalya: did you do a Console.Write or Writeline?
  • GeddalyaGeddalya

    Clint. seems like a writeline.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Unsderstandingarrays
    class Program
    static void Main(string[] args)
    //int[] numbers = new int[6];
    //numbers[0] = 4;
    //numbers[1] = 8;
    //numbers[2] = 15;
    //numbers[3] = 16;
    //numbers[4] = 23;
    //numbers[5] = 24;

    int[] numbers = { 4, 8, 15, 16, 23, 24, 26 };

    for (int i = 0; i < numbers.Length; i++)

    string[] names = { "Bob", "Steve", "Brian", "Chuck" };

    foreach (string name in names)

    string myText = "Now is the time for all good men to come to the aid of their country.";
    char[] charArray = myText.ToCharArray();
    // Array.Reverse(charArray);

    foreach (char myChar in charArray)


  • scarfacescarface

    WriteLine and Write are different. The WriteLine method quite literally does just that. Since the arrary is a character array, each letter is a new position in the arrary. When the loop runs this is what happens in 'pseudo-code'

    charArray position 1
    write character to console

    charArray position 2
    write character to console

    .................and so on

    Console.Write() method does the same without adding a new line after each loop


    line 47, change to:

  • Clint RutkasClint I'm a "developer"

    @scarface: thanks for helping!  Perfect response!

  • GedalyaGedalya

    Thanks Scarface. I guess i made a mistake, of assuming that he wrote Writeline.

  • I too used to be a big "Lost" fan Smiley

  • BilalBilal

    Hy Bob
    Your videos are really great. I am watching your videos from the past two years. Your videos helps me alot as a begginer.. Keep it up man... You are the best!!

  • MarcoMarco

    Hi Bob, thank for this course, you know how to explain in a clear way.
    someone never told you that look like A Team's Hannibal Smith? :)

    I also enjoy the Lost citation :)

  • Aniket SharmaAniket Sharma

    Sir How can insert the value in an array as we insert in the "C" language. or if any better way so please the solution.
    int i,a[20];
    for (i=0,i<6,i++)
    as i use to insert the value in this example , I want to insert the value in C# array (int[] array= new int[20]). I want to insert the value in this array by using the loops so please provide a solution

  • Clint RutkasClint I'm a "developer"

    @Aniket Sharma: It has been a long time since I've done a C console application so I'm going to do a bit more simple of a sample with strings rather than integers.  Also you have to watch your language when you're using terms like "inserting" into arrays.  That could be taken as you want to change your array size and actually append new items into it rather than just assign a value.

    string[] consoleData = new string[20];
    for (int i = 0; i < 6; i++)
    consoleData[i] = Console.ReadLine();
    for (int i = 0; i < 6; i++)

  • Thank you so much , without foreach loop i get the same value as yours but with a foreach i get an infinite chars  

  • Thank you so much for helping us to get the concepts C#

  • Clint RutkasClint I'm a "developer"

    @redar: can you paste in your code?  I may be able to help out

  • Hi Bob,

    I am a beginner, I don't have to say anything about the Series, as you already know they are really awesome!! helps me a lot, whenever I complete a video my enthusiasm and excitement increases after each and every video makes me to learn more and watch the next video. You must definitely be an awesome developer but at the same time you are Very Great/good/awesome Teacher too!!. Not everyone having so much of knowledge communicates so well and wants to share it for free. Hats off to your skills and to you.You have definitely become my icon not only because of your skills but because I believe you are a very good human being.

    Thanks a lot Bob Sir for the series.

  • ChopinChopin

    Bob, you've got the rear talent for teaching , Sir!
    I've got a question: what is value of "Length" in "numbers.Length"? If it is 5 as we assigned to array then "i < numbers.Length" should printout first four numbers: 4,8,15,16, skipping last 23, as 5<5 is false. What I am missing here?
    Thank you

  • Clint RutkasClint I'm a "developer"

    @Chopin: arrays have indices that are zero based, so you are doing i = 0, incrementing one each time , you'll do 0, 1, 2, 3, 4 the next iteration, i is increased to 5 which then is not less than the length of the array so the for loop exits.

  • ChopinChopin

    Thank U, Clint.
    Got it now. What im forgetting is that iteration starts at i=0!

  • samsam

    How to view or download "Source Code" from Microsoft Virtual Academy ? it's not working!

  • SamSam

    Microsoft Virtual Academy videos are not working on Google chrome Browser!
    please help?

  • Clint RutkasClint I'm a "developer"

    @Sam: raising internal, can you provide a link?  I can get the video to play in chrome for video 2.  Source code looks like it is getting blocked due to a popup warning in chrome.

  • Hi Bob,

    Thanks for the videos. I have one question about this one. In the end you use the Write technique as opposed to the WriteLine technique. As I was copying your code I used WriteLine by accident, but seems to give me the same result. I expected all the separate characters on separate lines but somehow that did not occur. Can you maybe clarify this?


  • npdnpd

    @Guust: Weird.. I tried using WriteLine instead of Write and it put all chars on separate lines.

  • Great stuff Bob thanks for your time!!!


    After writing the 1st block of code, instead of commenting out the Console.WriteLine, I simply modified it with the code you had provided, added the "for statement", but it would not run. Copied and pasted it inside the curly braces and it works. Fun to get in and play with it.


  • Hey BoB your tutorials are awesome i have been going through them frequently as i m new to c# i find this language interesting due to the way u have explained them . I am working hard to get through them as it requirement for my job . First time wen i heard i have to work on .Net i was like nah bt now that i have found out a good teacher like you i no its gonna go good .

    your doing a great job ! Happy days going on !

    God bless u have blessed life :)

  • BrianBrian

    Working my way through the series.

    Began programming in the 70's. Never liked C, C++ or VB.

    Acquired familiarity with C# through many developer events, but never could tolerate a thorough introduction - until I found this series (as you recommended it as a prerequisite for MS Store app development).

    Best tutorial series I've seen for any programming language!

    Still don't like C#; but can take it in 34 expertly presented portions. 9 down, 25 to go.


  • Thank you so much for this series. There is 1 thing I kinda miss: A task after each lesson to use what you already showed in the lesson?
    Also since I kinda need to understand the logic behind this I did a small program mixing the lessons a bit:

    Console.Write("Please type in the text you want to reverse and press Enter: ");
    string userInput = Console.ReadLine();
    char[] userText = userInput.ToCharArray();
    foreach (var userOut in userText)

    This gave me more context than the one you used in the video, as it incorporated letting the user to input the data to the array.

    Again ty so much for this series, finaly Im going to be able to code C# [H]

  • How can one express the equality of two different arrays? For example, say I had two arrays, one named arrayTest and one named arrayCheck. Could I do something like if (arrayTest == arrayCheck)? If not, what could I use?

  • Thanks for the video series, seems to be a great way to step into coding C#.  I have skirted the edges of Visual Studio for years with work inside MS SQL development.  I enjoy modifying the examples to extend my knowledge.  I wondered what else Array could do besides .Reverse so I typed it and the list of attributes was long.  I chose Sort and added this line (in different places) to get some additional gibberish:  Array.Sort(charArray);  [H]

  • JamesBJamesB

    Hi Bob,

    This is one the best programming series I have come across. So inspiring so enriching. I look forward to the next level. Thanks Channel 9 Team.

  • HassanHassan

    Awesome man ... :)

Remove this comment

Remove this thread


Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.