value-type

How to store a reference to an integer in C#?

Possible Duplicate: How do I assign by reference to a class field in c#? Hello everyone - tell me how to make this work? Basically, I need an integer reference type (int* would work in C++) class Bar { private ref int m_ref; // This doesn't exist public A(ref int val) { m_ref = val; } public void A...

Is there any other reason beside performance and readiblity of why System.String is a reference type instead of value type?

Why was String designed as a reference type instead of value type? From the modeling perspective I would have modeled it as a value type since it represents something without identity. It doesn't have distinguishing attributes. (E.g I can't make any difference between one string "a" and another string "a") I know that I would have ha...

How to override GetHashCode() for value types in a good way?

Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? As I understand it, there's a recommendation to override the base type GetHashCode() for my own value types. I have a hard time finding good resources on the actual how to implement a good hash code scheme for different kinds of value t...

Looking for a more elegant way to check for nullable value types.

To check if a value type is nullable I'm currently doing something like this: int? i = null; bool isNullable = i.GetType().ToString().Contains("System.Nullable"); Is there a more elegant way to do this? ...

Can I define an assignment operator in vb.net Structure?

I am having a structure that is actually a simple byte with more functionality. I defined it this way: Structure DeltaTime Private m_DeltaTime As Byte Public ReadOnly DeltaTime As Byte Get Return m_DeltaTime End Get End Property End Structure I want to have these two functionalities: Public ...

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...

Will structs and value types (like C#'s) be included in Java 7?

Will structs and value types (like C#'s) be included in Java 7? ...

What is the difference between C# & CLI when it comes in with value types and constructors?

I read recently that the C# and CLI standards define different ways to handle value types and constructors. According to the CLI specification value types can't have parameterless constructors, whereas in the C# specification value types have a default parameterless constructor. If, according to the CLI specification, you need to create...

C# value type with dynamic number of fields

The best way to explain my problem is with a code snippet: enum Resource { ..., Size } class ResourceVector { int[] values = new int[(int)Resource.Size]; public static ResourceVector operator + (ResourceVector a, ResourceVector b) {...} ... } We are using this type everywhere as though it were a value type. I.e. we...

Is it possible to create a reference-cycle using only value-types?

By way of explanation, take this value type in C#: struct ObjRef { public object Value; public ObjRef(object value) { Value = value; } } I can imagine an object graph where there are two boxed instances of this type, each holding a reference to the other. This is what I mean by a reference-cycle with only value-types. My ques...

C# value type casting: how it works?

Possible Duplicate: Why does this conversion doesn't work? Hi, i discovered a strange behaviour of the framework. This code throws an exception: byte a = 1; object b = a; Console.WriteLine(b.GetType()); Console.WriteLine((byte)b); Console.WriteLine((int)(byte)b); Console.WriteLine(Convert.ToInt32(b))...

Is a C# struct ever boxed when used as the return value of a function?

A simple question, but I haven't found a definitive answer on Stack Overflow. struct foo { int x; int y; int z; } foo Func() { return new foo(); } void Func2() { foo f = Func(); // did boxing and unboxing occur? } Is a C# struct (value type) always copied to the stack when returned fro...

Is this some kind of referencing problem? Value not sticking

Apologies for the appalling title. I have mocked up this code to mimic an issue I was encountering on a project. I want to know why the property status does not 'stick'. Stepping through the code I can even see it setting the property! Is it something to do with Structure being a value type? Here is the code, it is standalone. Impor...

value_type size

is there any ways of retrieving the number of elements in typename X::value_type where X is a vec of tuples? thanks ...

Where are ref value type parameters stored for asynchronous method calls in Microsoft's CLR?

I understand that this is an implementation detail. I'm actually curious what that implementation detail is in Microsoft's CLR. Now, bear with me as I did not study CS in college, so I might have missed out on some fundamental principles. But my understanding of the "stack" and the "heap" as implemented in the CLR as it stands today is...

how can i remove the value from a DateTime?

i have an existing DateTime? object that has a datetime in it. I want to remove the datetime value from it so when you ask "HasValue" it returns false? ...

Is creating a C# generic method that accepts (nullable) value type and reference type possible?

I want to create a simple method that accepts both value type and reference type parameters, i.e. int is value, and string is reference. So this is what I start with: public bool areBothNotNull<T>(T? p1, T? p2) { return (p1.HasValue && p2.HasValue); } So I want to be able to use it like this: var r1 = areBothNotNull<int>(3, 4);...