Please help me on this.
I am new to C# and structure
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dhiru
{
class Program
{
struct studentInformation
{
public string[,] student;
public studentInformation(int fValue, int lValue)
{
student = new string[5, 7];
for (int i = 0; i < 6; i++ )
{
for (int j = 0; j < 5; j++ )
{
switch (i)
{
case 0:
Console.WriteLine("Enter the student first name : ");
student[i, j] = Console.ReadLine();
break;
case 1:
Console.WriteLine("Enter the student last name : ");
student[i, j] = Console.ReadLine();
break;
case 2:
Console.WriteLine("Enter the student Address : ");
student[i, j] = Console.ReadLine();
break;
case 3:
Console.WriteLine("Enter the student city : ");
student[i, j] = Console.ReadLine();
break;
case 4:
Console.WriteLine("Enter the student state : ");
student[i, j] = Console.ReadLine();
break;
case 5:
Console.WriteLine("Enter the student country : ");
student[i, j] = Console.ReadLine();
break;
}
}
}
}
}
static void Main(string[] args)
{
string sFirstName = "";
string sLastName = "";
string sAddress = "";
string sCity = "";
string sState = "";
string sCountry = "";
studentInformation sInfo = new studentInformation();
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 5; j++)
{
switch(i)
{
case 0:
sFirstName = sInfo.student[i, j];
break;
case 1:
sLastName = sInfo.student[i, j];
break;
case 2:
sAddress = sInfo.student[i, j];
break;
case 3:
sCity = sInfo.student[i, j];
break;
case 4:
sState = sInfo.student[i, j];
break;
case 5:
sCountry = sInfo.student[i, j];
break;
}
}
Console.WriteLine("{0} {1} is a student comes from city : {2}, state: {3}, country: {4} and his address is {5}", sFirstName, sLastName, sCity, sState, sCountry, sAddress); //print the output
}
}
}
}
This code is throwing null reference exception which I know why but I don't know how to correct this other than using the for loop of struct in main method. I want to take user input in struct.