Check the parameter in construtor : Constructor : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Constructor »

 

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;
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Constructor