The best way is probably to have ShowData return a value: a string or an array of strings perhaps:
public string showdata()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Name: {0}\n", name);
sb.AppendFormat("Age: {0}\n", age);
sb.AppendFormat("Sal: {0}\n", sal);
return sb.ToString();
}
However, what I would do is change the name to ToString, and override the default version:
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Name: {0}\n", name);
sb.AppendFormat("Age: {0}\n", age);
sb.AppendFormat("Sal: {0}\n", sal);
return sb.ToString();
}
Then you can print it:
Console.Write(nc);
or whatever you want to do with it!