Created
January 13, 2012 16:33
-
-
Save arttuladhar/1607364 to your computer and use it in GitHub Desktop.
This way of instanciating a class is totally valid in C# 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication3 | |
{ | |
class Program | |
{ | |
public class Person{ | |
private string _firstName; | |
private string _lastname; | |
public Person() {} | |
public string Firstname { | |
get{ | |
return _firstName; | |
} | |
set | |
{ | |
_firstName = value; | |
} | |
} | |
public string Lastname | |
{ | |
get | |
{ | |
return _lastname; | |
} | |
set | |
{ | |
_lastname = value; | |
} | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Person p1 = new Person | |
{ | |
Firstname = "Jyoti", | |
Lastname = "Tuladhar" | |
}; | |
Console.WriteLine(p1.Firstname.ToString()); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment