Saqib Ullah

BootStrapper Know How

  Home  |   Contact  |   Syndication    |   Login
  93 Posts | 1 Stories | 336 Comments | 15 Trackbacks

News



Article Categories

Archives

Post Categories

Blogging websites

Favourite Blogs

Private Links

Sites

This is my C# class and its compatible with all .Net framework versions.
 public class Person
{
    // Fields
    private string _name;
    private int    _age;
    private string _city;
    private string _company;
 
    // Properties
    public string Name
    {
       get { return _name; }
       set { _name = value; }
    }
    public int Age
    {
       get { return _age; }
       set { _age = value; }
    }
    public string City
    {
       get { return _city; }
       set { _city = value; }
    }
    public string Company
    {
      get { return _company; }
      set { _company = value; }
    }
}
From the last bit of class code every thing is old so what is new.
 
Here is new technique in C# 3.0 to define properties in the terse and brief syntax like this,
Person  objPerson new Person {Name=”Saqib Ullah”, City=”Karachi”, Company=”InboxBiz”, Age=26}
 
I hope this post increase your C# 3.0 little bit.
 
posted on Sunday, April 22, 2007 9:09 AM

Feedback

# re: Never Before 4/22/2007 5:52 PM Shadowin
What was the point of doing this, besides maybe curbing those developers that get it in their head to write a constructor for every single possible way to initialize the object?

Here are two ways of doing the exact same thing:

Person person = new Person {Name=”Saqib Ullah”, City=”Karachi”, Company=”InboxBiz”, Age=26};

or

Person person = new Person();
person.Name=”Saqib Ullah”;
person.City=”Karachi”;
person.Company=”InboxBiz”;
person.Age = 26;


On second thought, it does appear the the new initializer is cleaner.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: