value-type Questions

3

Solved

In Java, there have always existed primitive types and references, but not value types. One of the goals of Project Valhalla is to explore and incubate feature candidates such as value types. I w...
Reversible asked 8/2, 2018 at 21:14

4

Solved

This is just a simple theoretical question out of curiosity. I have always been like a java fan boy. But one thing makes me wonder why java does not provide mechanism for creating objects on the st...
Leishaleishmania asked 18/9, 2014 at 2:37

2

Solved

Is it possible to subclass a generic struct in swift ? assume we have a struct: struct Foo<T> {} and I wana "subclass" it to add some functionality: struct Something {} struct Bar<F...
Stillwell asked 16/7, 2015 at 21:49

3

Solved

Let's say I want to have a value type of 7 bytes (or 3 or 777). I can define it like that: public struct Buffer71 { public byte b0; public byte b1; public byte b2; public byte b3; public byt...
Pish asked 21/5, 2010 at 10:57

7

Solved

Consider a function which returns two values. We can write: // Using out: string MyFunction(string input, out int count) // Using Tuple class: Tuple<string, int> MyFunction(string inp...
Baca asked 17/6, 2011 at 6:1

4

Solved

Value types behavior shows that whatever value we are holding cannot be changed through some other variable . But I still have a confusion in my mind about what i mentioned in the title of this po...
E asked 17/8, 2011 at 4:50

6

Solved

There is code: struct A { int b; } class B { A a; int b; } Questions are: Is a in B boxed or not? Is a in B located in stack or in heap? Is b in A boxed or not? Is b in A stack or in heap?...
Amass asked 5/10, 2011 at 8:34

17

Solved

Playing around with Swift, coming from a Java background, why would you want to choose a Struct instead of a Class? Seems like they are the same thing, with a Struct offering less functionality. Wh...
Neighboring asked 15/6, 2014 at 18:33

17

Solved

Some guy asked me this question couple of months ago and I couldn't explain it in detail. What is the difference between a reference type and a value type in C#? I know that value types are int, b...
Anthem asked 20/2, 2011 at 13:21

3

Solved

The where T : struct constraint lets one to limit the domain of acceptable type parameters to the set of value types (as compared to the superset of types including both value and reference types) ...
Heisler asked 26/3, 2017 at 2:27

8

Solved

I have a list of structs and I want to change one element. For example : MyList.Add(new MyStruct("john"); MyList.Add(new MyStruct("peter"); Now I want to change one element: MyList[1].Name = "b...
Poltroonery asked 9/9, 2008 at 10:23

9

Solved

Take the following example: string me = "Ibraheem"; string copy = me; me = "Empty"; Console.WriteLine(me); Console.WriteLine(copy); The output is: Empty Ibraheem Since it is class type (i.e. ...
Poaceous asked 2/9, 2011 at 12:24

6

Solved

Is int (aka Int32) an object , or a primitive in .NET (I'm not asking regarding int?)? I hit F12 on the saved word int and got : public struct Int32 : IComparable, IFormattable, IConvertible, I...
Strathspey asked 20/10, 2015 at 22:19

8

Solved

I know that value types should be immutable, but that's just a suggestion, not a rule, right? So why can't I do something like this: struct MyStruct { public string Name { get; set; } } public ...
Lenard asked 13/4, 2011 at 14:15

2

Solved

I know that swift will optimize to copy on write for arrays but will it do this for all structs? For example: struct Point { var x:Float = 0 } var p1 = Point() var p2 = p1 //p1 and p2 share the ...
Chickweed asked 19/4, 2017 at 4:29

6

Solved

I am a beginner to C# programming. I am now studying strings, structs, value types and reference types. As accepted answers in here and in here, strings are reference types that have pointers store...
Inflate asked 12/11, 2016 at 15:59

9

Solved

Consider the following code (I have purposefully written MyPoint to be a reference type for this example) public class MyPoint { public int x; public int y; } It is universally acknowledged (i...

6

Solved

WARNING: THIS CODE SUCKS, SEE ANTHONY'S COMMENTS Which is faster? 1. public bool IsValueType<T>(T obj){ return obj is ValueType; } 2. public bool IsValueType<T>(T obj){ retur...
Bangui asked 21/4, 2011 at 19:11

1

Solved

In .NET 5, I created a default webapi solution "WebApplication1", and I have an action in WeatherForecastController: [HttpGet] [Route("[action]")] public (bool,string) Test()...
Abscise asked 28/7, 2021 at 2:53

9

Solved

I'm trying to convert the value "0" ( System.String ) to its Boolean representation, like: var myValue = Convert.ToBoolean("0"); // throwing an exception here I've looked at the MSDN page, and i...
Raposa asked 25/4, 2013 at 2:30

9

Solved

In my serialiser/deserialiser, I have the following snippet: if (element_type.IsValueType && collection_type.IsArray) { try { GCHandle h = GCHandle.Alloc(array_object, GCHandleType.Pi...
Choctaw asked 13/5, 2012 at 19:42

8

Solved

I know languages such as C and C++ allow determining the size of data (structs, arrays, variables...) at runtime using sizeof() function. I tried that in C# and apparently it does not allow putting...
Cleric asked 17/11, 2011 at 19:41

2

Solved

Consider the following: var emptyValueList = new List<int>(); //any value type (long, float, any struct ...) var minimum = emptyValueList.Min(); This will throw an InvalidOperationExceptio...
Randazzo asked 29/12, 2015 at 9:17

4

Solved

I am using C# to call a DLL function. [DllImport("MyDLL.dll", SetLastError = true)] public static extern uint GetValue( pHandle handle, ref somestruct a, ref somestruct b); How can I pass a n...
Leasehold asked 5/3, 2013 at 6:41

5

Solved

I don't understand when to use AnyObject and when to use Any in Swift. In my case, I've a Dictionary [String: ???] ??? : Can be Int, Double, Float, String, Array, Dictionary Can someone explain m...
Renault asked 12/9, 2014 at 13:13

© 2022 - 2024 — McMap. All rights reserved.