9. How to program in C# - ARRAYS - Beginner Tutorial

Share
Embed
  • Published on Apr 26, 2015
  • We learn what arrays & lists are and how to use them. We also take a quick look at multidimensional arrays.
    ● Developer Forum: forum.brackeys.com/
    Difficulty of lesson: Novice.
    ····················································································
    Want to make powerful games, Windows and Mac software or mobile applications? Then this course is a great place to start.
    ····················································································
    ♥ Donate: bit.ly/1J85CgC
    ♥ Subscribe: bit.ly/1kMekJV
    ● Website: brackeys.com/
    ● Facebook: brackeys/
    ● Twitter: BrackeysTweet/
    ········································­­·······································­·­····
    ► All content by Brackeys is 100% free. I believe that education should be freely available to everyone. Want to support me in my mission?
    Donate here: bit.ly/1J85CgC
    ········································­­·······································­·­····
    ♪ Baby Plays Electro Games
    teknoaxe.com/cgi-bin/link_code_2.pl?326

Comments • 360

  • Tim Jaha
    Tim Jaha Month ago

    There is nothing to explain how to populate the arrays by user input.

  • Elizabeth from Grand Rapids

    there is font HTML displaying over the video.

    • Gaetano De Paola Second Channel
      Gaetano De Paola Second Channel 3 months ago

      Yeah, I was wondering what that was, too. I don't know, perhaps it's an oversight by Brackeys, or just TheXvid being a derp?

  • MIDI Man
    MIDI Man 4 months ago +1

    1:35 Roblox oof

  • Konrad SK
    Konrad SK 4 months ago +1

    sounds like we share nationality. Denmark :)??

  • Matteo van Zwieten
    Matteo van Zwieten 4 months ago

    Replay this over and over HAHAHAHAHA 6:59

  • Martin
    Martin 4 months ago +1

    array.lenght read only
    what can I do ??

    • Gaetano De Paola Second Channel
      Gaetano De Paola Second Channel 3 months ago

      You're welcome ^^

    • Martin
      Martin 3 months ago +1

      ​@Gaetano De Paola Second Channel ye or you can just label them and duplicate or delete them as you wish
      still thank you for the explanation,( a bit late for me, I did a videogame as a schoolproject)

    • Gaetano De Paola Second Channel
      Gaetano De Paola Second Channel 3 months ago

      Well, yeah, Length is a read only method, meaning it can only be used as a reference for something, to check for a condition, or similar things.
      But you cannot set the value of Length.
      In other words, selecting the method's name, via IntelliSense (a.k.a. that auto-completion menu that pops up when you're typing known keywords and stuff like that), you can see if the method in question has "get", "set", or both.
      If the method has only "get": it's a read only method. It can be read but not written on.
      If the method has only "set": it's a write only method. It can be written on, but not read. _[NOTE: to be honest I don't think having only "set" is reasonable, I'm just writing it here for the sake of completeness.]_
      If the method has both "get" and "set": it's both a read and write method. You can both read, and write on it.
      In this case, Length has only "get", so you can only read its value, but not modify it.
      For example, consider the following code:
      int[] array = new int[2]; // Declaring an array of 2 integers, called "array".
      int size = array.Length; // Declaring an integer called "size", and setting its value to array's Length, which is 2. The variable "size" is now equal to 2.
      Now this is all fine and dandy. It works, because I'm only reading the Length's value, not modifying it.
      But if, say, I wanted to set the Length's value, like this:
      array.Length = 3;
      That would just not work, because the value cannot be modified; it's designed like that.
      If you're looking to modify the value of the Length, look up for something called Dynamic Arrays. They're like normal Arrays, but the length is modifiable.
      To do that, you can just use Lists, as shown in this video, as you can add and remove values for them with ease.
      I hope this was helpful, or at least informative. Sorry for being lengthy (no pun intended, lol).
      If you have more questions, feel free to ask, I don't bite :D
      Thank you for reading!

  • Schrodinger's Cat
    Schrodinger's Cat 5 months ago

    This is so much like Java. I feel like it's the exact same language. Wow

  • Nickolas Hoover
    Nickolas Hoover 5 months ago

    can someone help me out? I have the following function (where rows and cols are initialized by the user in Main):
    public static void createGrid2 (int rows, int cols)
    {
    int[][] grid2 = new int[rows][cols]; //For some reason, the bracket containing cols is underlined and says invalid rank specifier, but rows is fine
    int i, j;
    for (i = 0; i < rows; i++)
    {
    for (j = 0; j < cols; j++)
    {
    grid2[i][j] = i + j;
    Console.Write(grid2[i][j] + ", ");
    }
    }
    return;

  • Omar Elghobary
    Omar Elghobary 6 months ago

    you need to change it don't ask me why :)

  • Ame Malik
    Ame Malik 6 months ago

    y i cant put my list to Random? is it because its from another directory (namespace) ?

  • Kenroytk
    Kenroytk 6 months ago

    20:27 Made my day xd.

  • Eva Inday Jay
    Eva Inday Jay 7 months ago

    how many spaces should be before write this code

  • Brisbane Stomp
    Brisbane Stomp 7 months ago

    how can i reduce my array list values from being 3 lines into just one? i.e numbers[0] = 12, [1] = 3, [2] = 5; i know its wrong but their must be a more compressed way???? thanks for the great video!!!!

  • uccidi
    uccidi 7 months ago

    cool video... but why i automatically got subtitles...in an arabic language?

  • Bananen9876
    Bananen9876 8 months ago

    Great tutorial!

  • devalt1
    devalt1 8 months ago +1

    "Wooh!"
    Instantly liked :) thank you for these awesome lessons.

  • Jsms101
    Jsms101 8 months ago

    excelent tutorial, outstanding basics, learning c# this way allows you to have stronger foundations for unity.

  • Antoun Kassouf
    Antoun Kassouf 8 months ago +1

    please anyone answer:
    i did not understand the 2d arrays/3d can anyone explain why and how the grid was made and thank you sorry for being annoying
    :)

  • issa wemba
    issa wemba 9 months ago +1

    great video!!!!Simple and understandable for everyone. I hate when tutorials use complex definitions the explain terms instead of break them down to the basics.
    Try updating some of these video using more diagrams.
    I know! i'm typing this in 2019! I had to comeback...

  • Mohd Asyraf
    Mohd Asyraf 9 months ago

    hi thom nice to see you

  • Gordon MacLeod
    Gordon MacLeod 9 months ago

    Would have been more useful if you did not make the 2d array square. I don't know if it is col, row or row, col:(

  • Rhys 'Yeast' Ross
    Rhys 'Yeast' Ross 10 months ago +1

    uhh you can't embed html into the captions dude

  • Itzhak Ramm
    Itzhak Ramm 11 months ago

    did anyone hear the "uh" in 12:56 lol

  • J Crook
    J Crook 11 months ago

    I have been developing for several years now and have become comfortable with different languages, although each day i try to learn and teach more. Your first 9 videos in this series have helped me learn a whole new understanding to OOP languages and now i can easily explain the code to a new learner without referencing some bullshit. Thank you for the series!

  • mory mo
    mory mo 11 months ago

    Can i date you ? 😁lol

  • Matthew Miles
    Matthew Miles 11 months ago

    Anyone else feel like these suddenly got way too confusing, previous were good

  • Swaraj Pethkar
    Swaraj Pethkar 11 months ago

    Jagged array syntax not working

  • Swaraj Pethkar
    Swaraj Pethkar 11 months ago

    I m not able to do jagged array code

  • the doe
    the doe Year ago

    @20:25 the way he said One Direction xD

  • the doe
    the doe Year ago

    He has Epic games launcher installed before it was famous , cool

  • Dragonfly Kode
    Dragonfly Kode Year ago

    I can't count how many useless Array videos I've watched...seems another one who just goes over the same basic shit...nothing new or diffrent.

  • Nenad Zaric
    Nenad Zaric Year ago

    This programming language is so annoying. Python is much simpler.

  • Ganiyu odunaiya
    Ganiyu odunaiya Year ago

    can someone please answer my question. when you use this types of ( ) brackets in c# or java what does it means, the code below am trying to do calculation i use this ( ) but i dont really know what am doing, i want to have the maincomplex number and call in the compl1 and 2 as variable to the complex number also giving maincomplex it own assignment. Any help on explanation would be helpful.

    Console.WriteLine(complex1);
    Console.WriteLine(complex2);
    Console.WriteLine(maincomplex);
    decimal complex1= 5 - 3;
    decimal complex2= 2 + 2;
    decimal maincomplex = 5 * 5 - ((6 * 100) - (complex1) / complex2);
    When i hover to either of any of the Console.WriteLine i get
    error cant use local variable before it declared.

    • antgrif55 VLOGS
      antgrif55 VLOGS Year ago

      Maybe try his?
      decimal complex1= 5 - 3;
      decimal complex2= 2 + 2;
      decimal maincomplex = 5 * 5 - 6 * 100 - complex1 / complex2;
      Console.WriteLine(complex1);
      Console.WriteLine(complex2);
      Console.WriteLine(maincomplex);

  • Dank Coder
    Dank Coder Year ago

    subtitles were messed up

  • EpicEthan Gaming
    EpicEthan Gaming Year ago

    I WANT THE WALLPAPER!!!

  • omer mero
    omer mero Year ago

    array -- wuhuu
    hahahahahahahaha.

  • Saz Dosanjh
    Saz Dosanjh Year ago

    a variable called "number" is really confusing, add an array called "numbers" and this is impossible to follow. If you had a girl would you name her "Girl"? I am only looking at this as a refresher, I used to code C# 10 years ago am looking to get back into it. So I have no problem with variables, arrays, methods etc but this explanation doesn't work for me.

  • Dapper Knight
    Dapper Knight Year ago

    Did this get outdated or something? I'm sitting here in 2018 after copying everything exactly and when I run it all I get is a black command window into the grid he got around 21:14, lol.

  • Haris Bashir
    Haris Bashir Year ago +4

    I hate udemy girl😫😫😫😫

    • جعفر
      جعفر 8 months ago +1

      @Mohammad Nadeem lol same

    • Mohammad Nadeem
      Mohammad Nadeem Year ago +3

      udemy girl ? I only get the udemy guy, maybe youtube thinks im gay

    • EpicEthan Gaming
      EpicEthan Gaming Year ago +1

      the udemy guy is even more annoying!

  • Email Closed
    Email Closed Year ago +1

    cant see what your a coding?? come on teacher some of us are beginners

  • Ayesha Muhammad
    Ayesha Muhammad Year ago +2

    Thanks for the videos. Through all the videos I have watched so far, I think the best tutorials you've ever made. Hats off!!!!

  • Netrip
    Netrip Year ago

    Instead of Console.WriteLine(); how about using "\n" for the generic windows newline?

  • Jentrihell
    Jentrihell Year ago +1

    brackeeeeeeeeeeys

  • Raman R
    Raman R Year ago +1

    Super teaching i love it.....👌

  • Grzechotnik
    Grzechotnik Year ago +1

    "We're gonna call it names". I bet he didnt like this arrray

  • L I N Z I
    L I N Z I Year ago

    I can't understand from multidimensional arrays little bit hard but will practice on it

  • Matt
    Matt Year ago

    this series has been a huge help to me. without you i probably would've had multiple headaches by now. up until a few weeks ago from when i posted this. the only experience i had with logic was logic within games like minecraft and littlebigplanet. it's good to move to more powerful software like unity and visual studio as i become a game developer.

  • L I N Z I
    L I N Z I Year ago

    6:48 why did we put i in number , number [i]??

  • Yujin Seol
    Yujin Seol Year ago

    didnt't know C# is so easy like this,

  • ohmj hi
    ohmj hi Year ago

    help!! can user insert data into lists? and how

  • Fred Yuldashev
    Fred Yuldashev Year ago

    How do you memorize all this? Is it just consistent repetition or you have a certain way in memorizing this?

  • Alex Lakatos
    Alex Lakatos Year ago

    Why not using sniplets?

  • John Dough
    John Dough Year ago +2

    Love your channel! Keep up the good work!

    • Gaetano De Paola Second Channel
      Gaetano De Paola Second Channel 3 months ago

      That's easy, but to be fair it wasn't that easy when I was starting out :D
      People who are seeing this comment; I advise you to try!

  • Slim Jim
    Slim Jim Year ago

    Living in my mom's basement trying to learn C# then hopefully make games in Unity.

  • Oğuzhan Avcı
    Oğuzhan Avcı Year ago

    Dude you are the real hero!

  • faht fak carl
    faht fak carl Year ago

    One direction

  • Death GOD 7
    Death GOD 7 Year ago +1

    He has Epic Game Launcher?
    Fortnite...............ummmm no it is Unreal Engine lol haha

  • Thurman Merman
    Thurman Merman Year ago

    I want to display the array in this format when it is compiled in the foreach loop :
    Cherry Caramel Coffee Mint
    Strawberry Banana Apple Cookie n creme
    Chocolate Chocolate Chip
    any suggestions ? Thank you

  • Thurman Merman
    Thurman Merman Year ago

    Is it possible to display a size 10 string array in a column format using a foreach loop only , any suggestions ? Thank you.

  • kegan
    kegan Year ago

    The x for loop should actually be nested within the y loop. The code as it is now will give you width for height and vice versa (try it yourself! use the code in this video and change either width or height so that they don't match)
    Here's the proper code (I also changed the *Console.Write(grid[x,y] + " ");* to *Console.Write("_|");* so that you can actually see a better visual representation of a grid:
    int[,] grid = new int[width, height];
    for (int y = 0; y < height; y++)
    {
    for (int x = 0; x < width; x++)
    {
    Console.Write("_|");
    }
    Console.WriteLine();
    }

    *ciao! :D*

    • kegan
      kegan Year ago

      You can take it one step further by adding user input to the beginning of your program :)
      Console.WriteLine("How many spaces wide would you like the grid to be?");
      int width = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("How many spaces tall?");
      int height = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("\n\n\n");