H
Henning
I'm completely new to C#, although I have some background in TurboPascal
many years ago.
What I need is the explanation of why the first example gets and "use of
unassigned variable" when the variable is referenced outside the while
loop, while the second example works ok.
[example1]
static void Main(string[] args) {
bool ok = true; int checkvalue;
while (ok) {
checkvalue = 5;
Console.WriteLine("checkvalue in while loop {0} ", checkvalue);
ok = false; }
Console.WriteLine("checkvalue after the while loop {0} ", checkvalue);
Console.ReadKey();
[example2]
static void Main(string[] args) {
bool ok = true; int checkvalue=0;
while (ok) {
checkvalue = 5;
Console.WriteLine("checkvalue in while loop {0} ", checkvalue);
ok = false; }
Console.WriteLine("checkvalue after the while loop {0} ", checkvalue);
Console.ReadKey();
It's not that I don't got a clue or assumption, but I need the exact and
correct explanation/definiton
many years ago.
What I need is the explanation of why the first example gets and "use of
unassigned variable" when the variable is referenced outside the while
loop, while the second example works ok.
[example1]
static void Main(string[] args) {
bool ok = true; int checkvalue;
while (ok) {
checkvalue = 5;
Console.WriteLine("checkvalue in while loop {0} ", checkvalue);
ok = false; }
Console.WriteLine("checkvalue after the while loop {0} ", checkvalue);
Console.ReadKey();
[example2]
static void Main(string[] args) {
bool ok = true; int checkvalue=0;
while (ok) {
checkvalue = 5;
Console.WriteLine("checkvalue in while loop {0} ", checkvalue);
ok = false; }
Console.WriteLine("checkvalue after the while loop {0} ", checkvalue);
Console.ReadKey();
It's not that I don't got a clue or assumption, but I need the exact and
correct explanation/definiton