J
Jo Segers
Hi,
I am learning C# and I get a compilerer error below, but I do not
understand why. Can somebody explain this?
Thanx in advance.
jo.
using System;
class TestApp
{
public static void Main()
{
// Application entry point
Console.WriteLine("App Start");
// Test 1
TestClass jo;
for(int i = 0; i < 5; i++)
{
jo = new TestClass();
jo.ShowAantal();
jo.ShowSen();
}
jo.ShowSen(); // <-- Here I get "Unable to initialise local variable
'jo'???
jo.ShowName();
Console.WriteLine("App End");
Console.ReadLine();
}
}
class TestClass
{
static System.Int32 InstanceCounter = 0;
public TestClass()
{
Console.WriteLine("[TestClass] constructed.");
InstanceCounter++;
}
public void ShowAantal()
{
Console.WriteLine("[TestClass] ShowAantal called...");
Console.WriteLine("[TestClass] Number of testclass instances: {0}",
InstanceCounter);
}
public void ShowSen()
{
Console.WriteLine("[TestClass] ShowSen called...");
Console.WriteLine("[TestClass] Dit is een testregel.");
}
public void ShowName()
{
Console.WriteLine("[TestClass] ShowName called...");
Console.WriteLine("[TestClass] name is {0}", this.ToString());
}
}
I am learning C# and I get a compilerer error below, but I do not
understand why. Can somebody explain this?
Thanx in advance.
jo.
using System;
class TestApp
{
public static void Main()
{
// Application entry point
Console.WriteLine("App Start");
// Test 1
TestClass jo;
for(int i = 0; i < 5; i++)
{
jo = new TestClass();
jo.ShowAantal();
jo.ShowSen();
}
jo.ShowSen(); // <-- Here I get "Unable to initialise local variable
'jo'???
jo.ShowName();
Console.WriteLine("App End");
Console.ReadLine();
}
}
class TestClass
{
static System.Int32 InstanceCounter = 0;
public TestClass()
{
Console.WriteLine("[TestClass] constructed.");
InstanceCounter++;
}
public void ShowAantal()
{
Console.WriteLine("[TestClass] ShowAantal called...");
Console.WriteLine("[TestClass] Number of testclass instances: {0}",
InstanceCounter);
}
public void ShowSen()
{
Console.WriteLine("[TestClass] ShowSen called...");
Console.WriteLine("[TestClass] Dit is een testregel.");
}
public void ShowName()
{
Console.WriteLine("[TestClass] ShowName called...");
Console.WriteLine("[TestClass] name is {0}", this.ToString());
}
}