Check the parameter in construtor
using System;
public class Class1 {
public static void Main(string[] args) {
Student student = new Student("AAA", 1234);
Console.WriteLine("Welcome new student {0}", student.GetString());
}
}
public class Student {
string sStudentName;
int nStudentID;
int nCreditHours;
public Student(string sName, int nID) {
if (sName == null) {
sName = "invalid";
}
sStudentName = sName;
if (nID < 0) {
nID = 0;
}
nStudentID = nID;
nCreditHours = 0;
}
public string GetString() {
string s = String.Format("{0}({1})",sStudentName, nStudentID);
return s;
}
}
Related examples in the same category