2013年5月28日 星期二

C# Fundation, Part 3 (Passing Parameter by Value or by Reference)

 

image

Reference Type passed by Value

#1

image

#2

image

 

Reference Type passed by Reference (ref keyword)

#1

image

#2

image

 

If Both Reference Type & Value Type passed by Value

image

If Both Reference Type & Value Type passed by Value, but new an instance

image

If Reference Type passed by Reference

image

If Value Type passed by Reference

image

If Value Type passed by Reference using ref keyword

image

If Value Type passed by Reference using out keyword

image

If Value Type passed by Reference using ref keyword, but no initial value assignment of variable

Compile error: Use of unassigned local variable xxx

image

ref & out keyword has following difference

1. ref must have initial value assignment before passing to method, if not we will see the error

2. out must change its value within the method implementation, if not we will see the error

 

Blog to read:

http://rapidapplicationdevelopment.blogspot.tw/2007/01/parameter-passing-in-c.html

http://www.dotblogs.com.tw/hunterpo/archive/2010/05/02/14978.aspx (in Chinese)

沒有留言:

張貼留言