CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2015
    Posts
    3

    Question Help on getting variable values from a loop

    Hello I'm new on this forum and also on C#, and I have a question I want to retrieve the values of every variable from a loop, something like this:

    Code:
                sbyte A = -115, B = -44, C = 97, D = 112;
                byte E = 224;
                short F = -10000, G = 1990, H = 20000;
                ushort I = 52130;
                int J = 4825932;
                uint K = 970700000;
                long L = -1000000, M = 123456789123456789;
    
                for (char c = 'A'; c <= 'Z'; c++)
                {
                    Console.Write(c);
                    Console.ReadKey();
                }
    How can I get this working?
    Thank you!

  2. #2
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    4

    Re: Help on getting variable values from a loop

    What about it isn't working?

    Works perfectly on my machine.
    It writes an A, waits for me to hit a key, then writes a B, waits for me to hit a key, then writes a C, waits... etc.

    You do realize that the Console.ReadKey() waits for you to hit a key?

  3. #3
    Join Date
    May 2015
    Posts
    3

    Re: Help on getting variable values from a loop

    Quote Originally Posted by marjanvenema View Post
    What about it isn't working?

    Works perfectly on my machine.
    It writes an A, waits for me to hit a key, then writes a B, waits for me to hit a key, then writes a C, waits... etc.

    You do realize that the Console.ReadKey() waits for you to hit a key?

    I want to retrieve the value of the variable. so instead of show "A" show "-115"

  4. #4
    Join Date
    May 2015
    Posts
    3

    Re: Help on getting variable values from a loop

    Also the limit should be 'M' on the for, but before adjusting that, I was trying to make it work

  5. #5
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    4

    Re: Help on getting variable values from a loop

    Then you need a way to "link" the character with the variable named as that character. One way to do so is to set up a list or a dictionary which you can then query using the character as the index or the key.

    Lists (arrays) and dictionaries however use a single type. In your case that could be the biggest numeric type you need. As you have both signed and unsigned variables, you may need to set up two lists/dictionaries linking the variable names with the actual variable values (letter A, and the value of A) and have a way to determine in which list/dictionary the value is stored.

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
  •  





Click Here to Expand Forum to Full Width

Featured