Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
50 views

I have a method that returns a doubly-boxed generic type. When that generic type is a wildcard, the return type is not the one that I expect. An object of type Codec<T> can produce a Box<Box&...
Estecka's user avatar
  • 399
1 vote
1 answer
88 views

I need to use two versions of base type in the same generic: nullable and non-nullable. Like int? and int, Guid? and Guid, DateOnly? and DateOnly and so on. Nullable type should be at the class ...
Doctor Coder's user avatar
  • 1,071
4 votes
1 answer
116 views

According to boxing on structs when calling ToString(), calling an unoverridden method on a C# struct causes it to be boxed. This is ultimately because of how the constrained callvirt IL instruction ...
palapapa's user avatar
  • 1,051
2 votes
0 answers
34 views

I am making a simple network messaging system, and I have designed it around using structs for any small messages (and I am trying to avoid boxing as much as possible). The system is already working, ...
Aman Anas's user avatar
3 votes
1 answer
81 views

The Kotlin Docs contains the following information. All nullable references to a are actually the same object because of the memory optimization that JVM applies to Integers between -128 and 127. It ...
EARTH H's user avatar
  • 67
0 votes
1 answer
116 views

In Rider Resharper suggests to simplify string interpolation. When doing so, the Heap Allocation Viewer plugin warns me about boxing allocation. And indeed, the IL code is different and when running ...
Meister der Magie's user avatar
0 votes
1 answer
84 views

I am trying to follow the SOLID principles in my new C# 12/.NET 8 project. I will start by providing an example: Given two separate assemblies AssemblyA and AssemblyB where AssemblyA defines an ...
patvax's user avatar
  • 659
4 votes
4 answers
286 views

To avoid confusion, I'm looking for the rule/JLS entry. I'm not asking why Double -> int would fail, I'm asking about the way it fails I'm aware of the lossy conversion, as I've mentioned in my ...
Vince's user avatar
  • 15.2k
1 vote
1 answer
63 views

I have the following method: public static bool EquivalentTo<T>(this T? current, T? compare) where T : class { if (current is null && compare is null) // both are null ...
IamIC's user avatar
  • 18.4k
0 votes
1 answer
98 views

I am somehow producing a C# object that contains another object structure. I am not sure how I can get hold of its content. I have an array whose value is {object[1,1]} and type object[,] If I ...
Douar Gwenn's user avatar
2 votes
3 answers
232 views

Update Jan 5, 2024: the answer at this link appears to show that the C# compiler completely removes the object cast when trying to cast a string to an object: https://stackoverflow.com/a/51381643/...
user3163495's user avatar
  • 3,968
5 votes
1 answer
109 views

I am learning Java. When I call go(x), I get ‘int’. Why not ‘Short’? public class test { public static void go(Short n) {System.out.println("Short");} public static void go(int n) {...
kolinunlt's user avatar
  • 345
3 votes
2 answers
356 views

I know that boxing then unboxing is computationally expensive, and it happens when casting a value type to object or other reference type then back to value type. However, does this happen when I'm ...
8749236's user avatar
  • 494
1 vote
1 answer
71 views

I try to understand the concept of boxing and testing for base types, especially with tuples. I have two objects from an external C# library that have different concrete types but share a common base ...
7enderhead's user avatar
0 votes
1 answer
492 views

Is it possible to get a pointer to a boxed unmanaged value type, without writing a large switch statement that does a cast for every supported type? Something like: object val; // Contains a ...
kaalus's user avatar
  • 4,582
-1 votes
1 answer
100 views

I often get confused with boxing and unboxing. I mean I understand that both of them mean casting from System.Object to a value type which inherits from it (e.g. System.Int32 or System.Double) or ...
user avatar
0 votes
0 answers
148 views

I wrote a code that can detect the differences between two pages, but I want the boxes close to each other to appear as a single box,I want to see it in the form of the purple box in the picture I ...
Ctnkaya's user avatar
  • 15
9 votes
3 answers
516 views

I couldn't find a definitive answer for this seemingly simple question. If I write a method like this: public Integer getAnInt() { int[] i = {4}; return i[0]; } is the return value autoboxed into ...
L. Blanc's user avatar
  • 2,320
1 vote
1 answer
1k views

I can't seem to compile the following code; I get the error: Cannot convert source type 'MyConcreteInterfaceThing' to target type 'T' How come? Here is the code: public interface IMyInterfaceThing { ...
Stefan Hendriks's user avatar
0 votes
0 answers
84 views

When I was setting the background colour of the TitleBar, I used ref new Color( ) because it is a Color^, but Color has no constructors to set the red colour. So I'm trying to change the R Field value ...
羅小雪's user avatar
0 votes
2 answers
117 views

I want to create a simple way to create a matrix-like structure for users. This means that the user can define rows and columns. For now its looks like this: var matrix = new() { new() { Item1, ...
Dvornik Xilosof's user avatar
-1 votes
1 answer
68 views

I am boxing an integer as an object (System.Object). Then if I assign a new value to the object within the same scope, the value of the object is getting updated. But, if I try to pass the object as ...
Nafiz's user avatar
  • 43
1 vote
2 answers
963 views

I'm a newbie with Rust and I bumped into some obstacles when dealing with closures, either when returning them from functions and or methods, either when I need to store them as struct fields. Let's ...
se7entyse7en's user avatar
  • 4,326
0 votes
0 answers
2k views

So I have a video inventory program, Where the user creates a object of the class video by initializing the constructor Video video=new Video(String name){ this.name=name } Now I have three more ...
user avatar

1
2 3 4 5
18