Wednesday 29 January 2014

Difference between Types and Type Members in C#

                                                                                                                                           Previous....
                                                                                                                                                   Next.....



In the example below Customer is the Type and private fields(_id, _firstName, _lastName), Properties(Id, FirstName, LastName) and GetFullName() method are type members.


public class Customer
{    
 #region Private Fields    
 private int _id;    
 private string _firstName;    
 private string _lastName;    
 #endregion    
 #region Properties    
 public int Id   
  {       
 get
 {
 return _id;
 }      
  set
 {
 _id = value;
 }    
 }    
 public string FirstName   
  {       
  get return _firstName;
 }         
set
 { _firstName = value;
 }   
  }  
   public string LastName   
  {       
  get
 {
 return _lastName;
 }         
set
 
_lastName = value;
 }    
 }    #endregion     
#region Methods  
public string GetFullName()   
  {       
  return this._firstName + " " + this._lastName;    
 }    
 #endregion
}
                                                                                                                                           Previous....
                                                                                                                                                   Next.....

No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...