M
Muhammad Aftab Alam
Hello All
The question might be somewhat stupid but I have tried for an hour and could
not get through it.
I am creating a console based application just to begin with C#
following is the code
namespace Student1
{
class ABC
{
private
string strname;
public void GetData()
{
Console.WriteLine("Enter your Name");
strname = Console.ReadLine();
}
public void Print()
{
Console.WriteLine(strname);
}
};
class Class1
{
[STAThread]
static void Main(string[] args)
{
ABC[] arr = new ABC[6];
arr[0].GetData(); // This Line gives exception?
arr[0].Print();
}
}
}
according to me it should display a string to get data then print it but the
an exception occurs.System.NullRefrenceException
the Message is "Object reference not set to an instance of an object."
best regards
Aftab
The question might be somewhat stupid but I have tried for an hour and could
not get through it.
I am creating a console based application just to begin with C#
following is the code
namespace Student1
{
class ABC
{
private
string strname;
public void GetData()
{
Console.WriteLine("Enter your Name");
strname = Console.ReadLine();
}
public void Print()
{
Console.WriteLine(strname);
}
};
class Class1
{
[STAThread]
static void Main(string[] args)
{
ABC[] arr = new ABC[6];
arr[0].GetData(); // This Line gives exception?
arr[0].Print();
}
}
}
according to me it should display a string to get data then print it but the
an exception occurs.System.NullRefrenceException
the Message is "Object reference not set to an instance of an object."
best regards
Aftab