-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: zubinraj76
Message 5 in Discussion


 
Early / Late Binding example in
C#
 
 
Consider we have an Order class like this,
with just one property called OrderNo
 
 public class
Order
 {
  private string
strOrderNo;
  
  public string
OrderNo
  {
   get
   {
    return
strOrderNo;
   }
   set
   {
    strOrderNo
=
value;
   }
  }
  
 }

(Get and Set members are important
here)
 
 
Below is the regular code which
uses early binding as we all know :
 
{
   Order objOrder = new
Order();
   objOrder.OrderNo = "111";
   MessageBox.Show(objOrder.OrderNo);
}
 
 
Below is the code which uses late binding to achieve the same as above
:
 
{
   object obj =
Activator.CreateInstance(typeof(Order)); 
   PropertyInfo
proInfo =
obj.GetType().GetProperty("OrderNo");
   
   proInfo.SetValue(obj,
"222", null);
 
   MessageBox.Show((proInfo.GetValue(obj,
null)).ToString());
}
 
 
Note:
Early binding always have higher performance as the
compiler will know beforehand what type of the object will be created and can
make optimizations accordinly.
 
Moreover, the VB.Net compiler (and c# compiler)
implements late binding by adding some helper functions which will
definitely have a hit on the performance.
 
Regards,
Zubin.
 
(mailto:[EMAIL PROTECTED])
 
 
 




From: mag_mani
[mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 19,
2004 3:44 PM
To: BDOTNET
Subject: late binding in
c#




  
  
    
    New Message on BDOTNET
  
    

late
  binding in c#


  
    
    
      Reply

      
        
          
          
             
            Reply to Sender   Recommend 
            Message 1 in Discussion
            
    
      
        
          
          
            From: mag_mani 
          
            

              Hi,
               
              can any one of you tell me where late binding is implemented
              in #, examples?
               
               
View other groups in this
  category. 



-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to