tagged [value-type]
Reference types vs Nullable types ToString()
Reference types vs Nullable types ToString() Could someone please be kind enough to explain why calling `ToString()` on an empty reference type causes an exception (which in my mind makes perfect sens...
- Modified
- 3 Aug at 07:53
How to determine if a string is a number in C#
How to determine if a string is a number in C# I am working on a tool where I need to convert string values to their proper object types. E.g. convert a string like `"2008-11-20T16:33:21Z"` to a `Date...
- Modified
- 26 Mar at 05:6
Indexers in List vs Array
Indexers in List vs Array How are the Indexers are defined in List and Arrays. `List lists=new List();` where `MyStruct` is a Structure. Now Consider `MyStruct[] arr=new MyStruct[10];` `arr[0]` gives ...
- Modified
- 15 Jul at 10:24
Convert.ToBoolean fails with "0" value
Convert.ToBoolean fails with "0" value I'm trying to convert the value `"0"` ( `System.String` ) to its `Boolean` representation, like: I've looked at the [MSDN page](http://msdn.microsoft.com/en-us/l...
- Modified
- 25 Apr at 12:2
Is it possible to clone a ValueType?
Is it possible to clone a ValueType? Is it possible to clone an object, when it's known to be a boxed ValueType, without writing type specific clone code? Some code for reference The partical issue I ...
- Modified
- 6 Jun at 20:6
C#: Getting size of a value-type variable at runtime?
C#: Getting size of a value-type variable at runtime? I know languages such as C and C++ allow determining the size of data (structs, arrays, variables...) at runtime using sizeof() function. I tried ...
- Modified
- 17 Nov at 19:41
Detailed Explanation of Variable Capture in Closures
Detailed Explanation of Variable Capture in Closures I've seen countless posts on how variable capture pulls in variables for the creation of the closure, however they all seem to stop short of specif...
- Modified
- 25 Mar at 22:2
C# Generic constraints to include value types AND strings
C# Generic constraints to include value types AND strings I'm trying to write an extension method on IEnumerable that will only apply to value types and strings. However 'string' is not a valid constr...
- Modified
- 5 Jan at 16:9
Is Nullable<int> a "Predefined value type" - Or how does Equals() and == work here?
Is Nullable a "Predefined value type" - Or how does Equals() and == work here? For my own implementation of an Equals() method, I want to check a bunch of internal fields. I do it like this: I would a...
- Modified
- 12 Sep at 07:48
Local variable (int) might not be initialized before accessing
Local variable (int) might not be initialized before accessing I have the following method defined in a class: What's strange to me is that I'm getting a "Local variable might not be initialized befor...
- Modified
- 18 Jun at 17:49
In C#, why can't I modify the member of a value type instance in a foreach loop?
In C#, why can't I modify the member of a value type instance in a foreach loop? I know that value types should be immutable, but that's just a suggestion, not a rule, right? So why can't I do somethi...
- Modified
- 5 Feb at 21:43
Changing the value of an element in a list of structs
Changing the value of an element in a list of structs I have a list of structs and I want to change one element. For example : Now I want to change one element: However, whenever I try and do this I g...
- Modified
- 2 Jun at 10:31
Changing the 'this' variable of value types
Changing the 'this' variable of value types Apparently you can change the `this` value from anywhere in your struct (but not in classes): I've neither seen this before nor ever needed it. Why would on...
- Modified
- 23 May at 12:1
Extension methods defined on value types cannot be used to create delegates - Why not?
Extension methods defined on value types cannot be used to create delegates - Why not? Extension methods can be assigned to delegates that match their usage on an object, like this: ``` static class F...
- Modified
- 27 Jun at 14:29
Why must fixed size buffers (arrays) be declared unsafe?
Why must fixed size buffers (arrays) be declared unsafe? Let's say I want to have a value type of 7 bytes (or 3 or 777). I can define it like that: A simpler way to define it is using a fixed buffer `...
- Modified
- 1 Mar at 20:8
Do interface variables have value-type or reference-type semantics?
Do interface variables have value-type or reference-type semantics? Do interface variables have value-type or reference-type semantics? Interfaces are implemented by types, and those types are either ...
- Modified
- 16 Dec at 22:53
When would a value type contain a reference type?
When would a value type contain a reference type? I understand that the decision to use a value type over a reference type should be based on the semantics, not performance. I do not understand why va...
- Modified
- 28 Nov at 21:22
Can AutoMapper Map Between a Value Type (Enum) and Reference Type? (string)
Can AutoMapper Map Between a Value Type (Enum) and Reference Type? (string) Weird problem - i'm trying to map between an and a , using AutoMapper: Don't worry that im using `.ToString()`, in reality i...
- Modified
- 12 Apr at 06:58
Is creating a C# generic method that accepts (nullable) value type and reference type possible?
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 and parameters, i.e. int is value, and string is refe...
- Modified
- 22 Apr at 03:12
Generic constraint on T to be reference type and value type simultaneously?
Generic constraint on T to be reference type and value type simultaneously? I have a problem with understanding how generic constraints work. I think I am missing something important here. I have encl...
- Modified
- 15 Oct at 11:58
Why can't I write Nullable<Nullable<int>>?
Why can't I write Nullable>? The definition of [Nullable](http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx) is: The constraint `where T : struct` implies that `T` can only be a value type. So I v...
- Modified
- 29 Sep at 12:28
Is object a reference type or value type?
Is object a reference type or value type? I have still doubts about `object`. It is the primary base class of anything, any class. But is it reference type or value type. Or like which of these acts i...
- Modified
- 28 Jul at 09:14
Using Structs with WCF Services
Using Structs with WCF Services I'm currently interacting with a service I did not write and find myself inspired to ask to see if my annoyance is warranted. I've in past always used classes - probab...
- Modified
- 18 Jun at 19:40
Details on what happens when a struct implements an interface
Details on what happens when a struct implements an interface I recently came across this Stackoverflow question: [When to use struct?](https://stackoverflow.com/questions/521298/when-to-use-struct-in...
- Modified
- 23 May at 12:7
When does using C# structs (value types) sacrifice performance?
When does using C# structs (value types) sacrifice performance? I have been playing with structs as a mechanism to implicitly validate complex value objects, as well as generic structs around more com...
- Modified
- 9 Dec at 15:30