-
May 23rd, 2015, 01:24 PM
#1
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!
-
May 23rd, 2015, 03:07 PM
#2
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?
-
May 23rd, 2015, 04:57 PM
#3
Re: Help on getting variable values from a loop
Originally Posted by marjanvenema
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"
-
May 23rd, 2015, 05:00 PM
#4
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
-
May 24th, 2015, 05:42 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|