Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can some one please explain the code.

C#
public Racer(int id, string firstName, string lastName, string country) :this(id, firstName, lastName, country, wins: 0) { }


What I have tried:

Can some one please explain the code.
Posted
Updated 7-Mar-16 19:35pm
Comments
Jim Meadors 8-Mar-16 1:21am    
You really should start with a beginner book and just work your way through it.
Sambit_Sahoo 8-Mar-16 1:22am    
I am a beginner

1 solution

In your code "this" is used overload the constructor.The this() syntax instructs the compiler to insert the specified constructor that matches the parameter list specified.

eg:

C#
  public class User{
       string firstName,lastName;
       int Age;

        public User(string FName,string LName):this(FName,LName,Age=0)
         {
             firstName=Fname;
             lastName=LName;
             this.Age=Age;
         }
   }
class Program
{
    static void Main()
    {
	
	User obj1= new User("abc","xyz");
	User obj2= new User ("abc","xyz",19);
    }
}

Output:
        1] abc, xyz, 0
        2] abc, xyz, 19
 
Share this answer
 
v2
Comments
Sambit_Sahoo 8-Mar-16 1:37am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900