Sunday, November 9, 2008
Difference between ref and out keyword in C#
Difference #1
A variable passed as a ref parameter must be initialized before it is passed to the method. A variable passed as out parameter need not be initialized (but you may initialize it if you so desire) before it is passed to the method.
Difference #2
ref - this keyword passes a variable as a reference to the method which changes its value as per program logic (but changing value is optional).
out - this keyword passes a variable as a reference to the method which must change its value as per program logic before returning any value or before using the passed variable.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment