what is the difference between passing a value object by
reference and a reference object by value?
Answers were Sorted based on User's Feedback
Answer / c
I am sorry ...above is not correct....actually to pass
reference type as value we need to use clonable/ copy
constructor ...otherwise in C# it is not possible to pass
object as value
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / ashish diwakar
..........For above example..............
Well I skip to add .ToString in my above answer.
We can not pass Reference type objects directly to a method.
So to pass value of sb variable we need to use following
code:
Display(sb.ToString());
..........For above example..............
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ashish diwakar
Value Objects are the objects that contain the data as
objects such int, string, etc...
Reference Objects are the objects that contain the data as
reference such as StringBuilder,etc...
When a Value object is passed as reference the reference of
the object is passed to the method (which means that any
change made to variable will be reflected on the original
variable).
But when a Reference Object is passed by value Like :
StringBuilder sb =new StringBuilder();
sb.Append("hello");
Display(sb);
any change made on sb inside Display function will not
change value of sb.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / c
When you pass object by reference to any method, you are
passing reference (base pointer) to method. Any changes
done on this object will get reflected in object in caller.
When you pass any object by value, you are passing copy of
the object and not the reference.
| Is This Answer Correct ? | 1 Yes | 2 No |
How can I create a process that is running a supplied native executable (e.g., Cmd.exe)?
Is it possible to force garbage collector to run?
explain the nature of the assembly work?
What?s the .NET datatype that allows the retrieval of data by a unique key?
What does assemblyinfo.cs consists ?
Why do we use methods in c#?
What is multicast delegate in c# ?
Which property do we set on a Combo Box to display data on it prior to setting the DataSource ?
What are three test cases you should go through in unit testing?
1 Answers Siebel Systems, Wipro,
What is the usage of transponders?
What is the difference between interface and functional interface?
Is int a struct in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)