Creating Arrays of Values - 09
- Posted: Nov 21, 2011 at 9:13 AM
- 64,326 Views
- 43 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
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.
Already have a Channel 9 account? Please sign in
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
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.
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!
@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.
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!
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.
Glad you're enjoying these.
@BobTabor: Easy to understand videos, Thanks Bob
@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!
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");
}
else
{
Console.WriteLine(s + " is not a palindeome");
}
Console.ReadLine();
}
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...
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();
Array.Reverse(n);
string n2 = new string(n);
//string n2 = n.ToString();
if (a == n2)
Console.WriteLine("palindrome");
else
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!
Hey Bob your VIDEOS are awesome.
Just wanted to bring to the notice of the other users:
Console.WriteLine(myChar);
and
Console.Write(myChar);
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!
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!
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.
http://msdn.microsoft.com/en-us/library/2yd9wwz4(v=vs.71).aspx
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)?
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:
http://stackoverflow.com/questions/1391672/what-is-the-maximum-size-that-an-array-can-hold
(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:
http://msdn.microsoft.com/en-us/library/ms165473(v=vs.90)
Good luck!
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:
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
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!
@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:
System.Console.Writeline();
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 :)
hi Bob,
Thanks for sharing your knowledge and understanding with the world!!!
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.
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 ??
wow. really love you work, looks like im the first Nigerian hear, thanks a lot
Bob,
Fantastic video series! I'm picking things up much faster than I anticipated. I really appreciate them.
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?
Great Series, i have gone through C# and HTML5 series. it saves my precious hours which i needed to spend reading books.
Los siguientes ejemplos son en español sobre arreglos unidimensionales y bidimensionales
Another example using a didimensional array:
https://www.youtube.com/watch?v=Pn1VKYvnp_A
El siguiente ejemplo de código está en español sobre arreglos unidimensionales en C#
Example of code using a simple array:
https://www.youtube.com/watch?v=Wkenbl57aws
Remove this comment
Remove this thread
close