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

New Message on BDOTNET

-----------------------------------------------------------
From: rags_rao
Message 4 in Discussion


You will c no diff b/w byval,byref on refrence types (again! string is an exception). 
but in situations like the one given shown below u will see a diff. 
byval: passes a copy of refernce  
byref:  a magaged pointer (same as  &params in c++) is passed 
public class MyObject
{
    public int x; 
    public static void Main()
    {
        MyObject obj1 = new MyObject(),obj2 = new MyObject(),obj3=obj1;
 //2 objects. obj1 points to 1st one. obj2,3 point to 2nd one
        obj1.x = 
        obj2.x = 10;
        ModifyByRef(ref obj1);
        ModifyByVal(obj2);
 
        if(obj1!=null) System.Console.WriteLine(obj1.x);
        else System.Console.WriteLine("obj1 is null");//null because a managed pointer 
to same reference was passed 
        if(obj2!=null) System.Console.WriteLine(obj2.x);//no problem copy of refrence 
was passed
        else System.Console.WriteLine("obj2 is null"); 
        if(obj3!=null) System.Console.WriteLine(obj3.x);//but the underlying object is 
still modified
        else System.Console.WriteLine("obj3 is null"); 
    } 
    public static void ModifyByRef(ref MyObject obj)
    {
        obj.x = 20;
        obj = null;
    }
    public static void ModifyByVal(MyObject obj)
    {
        obj.x = 20;
        obj = null;        
    } 
}


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

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