Entries:
Comments:
Posts:

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

for Iterations - Day 1 - Part 14

Download

Right click “Save as…”

When working with data or objects (such as controls) in applications, you often need to loop or, rather, iterate through groups. This video explains how to work with a simple “for iteration” statement. Since we'll be working with lots of different groups (such as collections of objects and collections of data) we’ll need to understand a little about how to navigate through the collection, or list, of those items.

Download the source code in c#

Download the source code in VB.Net

Follow the Discussion

  • jamesjames

    Hi Bob, great series of videos. just finished day 1 and coming back to this video because....
    i understand the theory of what the for loop is doing etc just fine. but this line i get confused...
    message = message + i.ToString() + System.Environment.NewLine;
    when i go through loop in my head i come to the conclusion you shouldnt need the "message +" part.. as in effect "message" has no value/string. yet when you remove it only "9" is displayed. also if you put "message = i.ToString() + message + System.Environment.NewLine;"  the NewLine is being initiated.
     
    if you could clear this up for me i would appreciate it! cheers 

  • jamesjames

    @james: sorry the .NewLine is NOT being initiated....

  • Clint RutkasClint I'm a "developer"

    @james: System.Environment.NewLine doesn't have to be initiated.

    He did create message and on every loop, he is recreating message with what was there, the loop counter, then a new line character.  Without the new line character there, it would look like this:
    56789

    instead of:
    5
    6
    7
    8
    9

  • KristianKristian

    @james:  you could also use message +=  i.ToString() + System.Environment.NewLine;
    This is the same as message = message + i.ToString() + System.Environment.NewLine;

  • ChristianChristian

    Yes I have to say overall the concept was clear but the lines of code were very unclear to me... More clarification would be better... for example
    when the variable is set to this string userValue = myTextBox.Text = "2";
    myResultReturned.Text = "You have won a million dollars";
    LOL, I know this is probably wrong but the point I am asking/illustrating is that why does the first line take a value in and why does the second line read a value out... how does the code know the difference of what it is displaying / running onto the screen versus taking in???

  • I have no idea what I am doing wrong. This is my code: 

    private void myButton_Click(object sender, RoutedEventArgs e)

           {

    string message = "";

    for (int i = 0; 1 < 10; i++)

               {

                   message = message + i.ToString() + System.

    Environment.NewLine;

                }

                myTextBlock.Text = message;
    and for some reason it has a green line under myTextBlock and said there is unreachable code detected. What am I doing wrong?

  • shamelesstoadshamelessto​ad

    @magicwin31: try to change from this  for (int i = 0; 1 < 10; i++) to this for (int i = 0; i < 10; i++)

  • @shamelesstoad that worked, thank you so much.

  • JorgeJorge

    @Christian, thats because the first line is used with a textBox, wich takes values "in", and the second line is used with a textBlock, wich takes values "out".

  • JorgeJorge

    There's something unclear to me,
    Why does the next code just writes down "9"? I mean, shouldnt it start with "1", print it, goes for the "2", prints it and so? I tried this code as i've done it several times in Java and it does print the whole secuence instead of just "9", so why isnt this working here?
    privatevoid myButton_Click(object sender, RoutedEventArgs e)
            {
    for (int i = 0; i < 10; i++)
                {
                    mytxtBlock.Text = i.ToString() + System.Environment.NewLine;
                }
            }
     
     

  • JorgeJorge

    EDIT: Actually it should start with "0" :P

  • Griffin WiebelGriffin Wiebel

    These videos are helping me not only learning the WP7 development process, but C# at the same time!

Remove this comment

Remove this thread

close

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.