Arrays
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Arrays

  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Red face Arrays

    Hello

    Have a simple question. I'm new to programming so bear with me. I want to create an array that is equal to the sum of two ints.

    example


    int smoking = 9;
    int nonSmoking = 5;
    int rooms[];

    I want my array to equal the sum of those two variables. But yes I could just declare it 14. I'm asking my user for the number of available rooms storing it in the smoking or nonsmoking variable. Once the input is received I want those two variables to be the length of my array.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,000

    Re: Arrays

    Code:
    int[] rooms = new int[smoking + nonsmoking];
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Arrays

    Better yet; don't use an array at all. I write C# quite a bit and I never use arrays. Really, it's very rare to use them in 'real' code.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  4. #4
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,000

    Re: Arrays

    ...? I use them sometimes...

    Do you just always use List<T>?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Arrays

    Yeah, I have to really try hard to find a reason to use raw arrays in C#. interop scenarios or the return type of some method in an API I don't control come to mind, but that's really it.

    There's really just no good reason to declare an array when you have generic containers that don't slow down performance.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center