reference-types

C#, Copy one bool to another (by ref, not val)

Hi folks. I am at a brick wall here. Is it possible to copy one bool to the ref of another. Consider this code . . . bool a = false; bool b = a; b is now a totally seperate bool with a value of false. If I subsequently change a, it will have no effect on a. Is it possible to make a = b by ref ?How would I do that ? M...

How do ValueTypes derive from Object (ReferenceType) and still be ValueTypes?

C# doesn't allow structs to derive from classes, but all ValueTypes derive from Object. Where is this distinction made? How does the CLR handle this? ...

.NET strings and reference type parameters

I was wondering if any one could explain this code to me... public void SomeMethod() { StringBuilder sb = new StringBuilder(); AppendFoo(sb); String foo = sb.ToString(); // foo is "foo" String s = String.Empty; AppendBar(s); String bar = s; // bar is empty } public void AppendFoo(StringBuilder x) { x.Appen...

Why does a reference type is not initialized to null ?

Check this code.. string str; if (str.Contains("something..")) { } Compiler throws this error for this code Use of unassigned local variable 'str' Why does a reference type is not initialized to null ? Just want to know out of curiosity. I'd also want to know what happens for code below. how does this assignme...

pass by reference without the ref keyword

I'm not a veteran in socket programming, so while analyzing code I found in a database API I came across this code public static void WriteInt(int i, NetworkStream bufOutputStream) { byte[] buffer = new byte[IntSize]; WriteInt(i, buffer, 0); bufOutputStream.Write(buffer, 0, buffer.Length); } pu...

.NET Parameter passing - by reference v/s by value

I'm trying to validate my understanding of how C#/.NET/CLR treats value types and reference types. I've read so many contradicting explanations I stil This is what I understand today, please correct me if my assumptions are wrong. Value types such as int etc live on the stack, Reference types live on the managed heap however if a refer...

Is Guid considered a value type or reference type?

Hi folks, Guids are created using the new keyword which makes me think it's a reference type. Is this correct? Guid uid = new Guid(); Are Guids stored on the heap? ...

When to use primitive and when reference types in Java

In which case should you use primitive types(int) or reference types (Integer)? This question sparked my curiosity. ...

Where are value types defined in a reference type stored (heap or stack) ?

Are the value types defined inside a reference type stored on the heap or on the stack? If stored on the heap, then when are value types stored on the stack? If stored on the stack, then what goes inside the heap as everything ends at a value type in the end? ...

From where can i get CTS hierarchy ? where does interface type fits in the CTS hierarchy

It says there are basically two types 1) Value type and reference type. all value types are dereived from system.valuetype 1) Is there any thing like system.referencetype , because every CTS hierarchy i have seen shows two types below system.objects , a Valuetype and a Referencetype My understanding is all types that are derieved from...

Reference and Value types scenario

I've been playing around trying to thoroughly understand Reference and Value types. Just when I thought I had it, I came across this scenario... I created a class that would contain a single object. class Container { public object A {get; set;} } When I create an instance of this Container class (a) I am creating instance of a re...

Loaded Entity not being passed back

Hi all, This is probably a complete noobie error. My deepload is loading my related entitied fine and T Entity is correctly populated, but when I go back to the original call it hasnt kept the updates? Now I'm sure EntityObjects are reference types (stupid question, but im doubting myself here) So I shouldnt need to pass it back. he...