Thursday, April 19, 2007

ref or out ? هل تعرف إستخدامهم

if we want pass a variable to a method as reference so the original value affected
من الاخر بص على المثال ده

int value1 = 5 ;
int value2 ;


واحد معملوا intialize
والتانى لأ ... متعرف بس

وتخيل إن عندنا ثلاثة دوال أو methods

void public increaseR (ref int x){


x = x+1 ;


}

void public increaseO (out int x){

x= 20 ;
x = x+1 ;


}

void public increase (int x){


x = x+1 ;


}


---------------------------------------------------------------------
لو إحنا جربنا الحاجات دى ياترى هاتدينا إيه ؟

increaseR (ref value1) ;
increaseO (out value2) ;

فى الحالة الأولى القيمة الأصلية هاتتغير للأثنين فى البرنامج كله
value1 = 6
value2 = 21


increase(value1) ;
increase(value2) ;
فى الحالة الثانية القيمة الأصلية مش ها تتغير للأثنين فى البرنامج كله
value1 = 5

vaue2 --- gives what ??? and why ???

0 Comments:

Post a Comment

<< Home