Click here to Skip to main content
15,923,376 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello the C/C++ implementation is :

C++
public class Person 
{
   int Id;
   Person(int a):Id(a)
   {
   }

}


please could someone provide me with the C# implementation of the same

What I have tried:

I have tried searching google and it seem that in C# we do not have this option. I want to confirm this.
Posted
Updated 14-Jun-16 3:51am
v2

C#
public class Person 
{
   int Id;
   Person(int a)
   {
        Id = a;
   }
 
}


or "this.Id = a" depending on style.
 
Share this answer
 
>I want to confirm this.

Confirmed: the way would be to put the initialisation to constructor like this:

C#
public class Person
{

    public Person() { }

    public Person(int _id)
    {
        id = _id;
    }

    public int id { get; set; }
}
 
Share this answer
 

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