Skip to main content
0 votes
0 answers
47 views

I was following a video to create small Visual Studio project for an alternate data entry. The video tutorial was on Visual Studio 2019 Blazor project and I'm on 2022 - so some slight variation. Code ...
user avatar
2 votes
1 answer
93 views

I was trying to figure this out using the Sharplab online C# decompiler but I am not entirely sure if I was understanding the output correctly. Recently in some code I was forwarding an object to some ...
baltermia's user avatar
  • 1,427
0 votes
1 answer
72 views

I saw in Microsoft learn site here option of use primary constractor body with this example: public class C(int i, string s) : B(s) { { if (i < 0) throw new ArgumentOutOfRangeException(...
אפרת's user avatar
2 votes
2 answers
97 views

Say you have public class Garage { public bool AddCar(Car car) { //omitted for brevity } } you add it as services.AddScoped<Garage>(); now you want to inject it into Car class: public ...
Aeseir's user avatar
  • 8,582
0 votes
1 answer
207 views

I was having a azure function and it's working fine and I have changed that to primary constructor and it's working perfectly fine on my local envrionment but while deploying that using the az ...
Imran Ahmad Shahid's user avatar
3 votes
1 answer
1k views

What is right: class MyClass(IInjectable _injectable) {} or class MyClass(IInjectable injectable) {} On the one hand, we have private field. On the other hand, this is constructor parameter's name.
Ryunten's user avatar
  • 103
0 votes
1 answer
140 views

IDE0290 suggests the use of primary constructors, but if one of the parameters happens to a IDisposable injected and you use readonly backup fields to store them, a CA2213 warning is generated public ...
Vincent Ripoll's user avatar
1 vote
2 answers
218 views

I'l admit that our testing framework would benefit from a significant refactor and this could be solved by better DI. However, I need to work with what I have for now. As part of the testing framework,...
Hand-E-Food's user avatar
  • 12.9k
0 votes
2 answers
301 views

In C# now (I'm not certain when this was added to the spec) we can declare a class without a body: public class MyClass; If I create an instance, though, I can't do anything with it. I thought it ...
rory.ap's user avatar
  • 35.7k
0 votes
1 answer
59 views

I've implemented the Result pattern for error handling in C# using record types, as shown in the code snippet below: namespace WebApi.Utils { public struct Roid { } public record Result<...
softshipper's user avatar
  • 34.3k
10 votes
1 answer
6k views

I noticed that a snippet like the below one, it marks the property initialization with a warning. public sealed class C(int a) { public int A { get; } = a; //<--here public int Sum(int b) ...
Mario Vernari's user avatar
1 vote
1 answer
1k views

How do you initialise a class using the C#12 primary construtor syntax. I know how to do it using dependency injection but cant find any docs showing how to do it with a normal class. here is what I ...
tase akpo's user avatar
0 votes
1 answer
446 views

Problem When creating a class with a primary constructor, the quick actions for adding another parameter in the constructor do not work as expected. The actual assignment of the constructor parameter ...
NTE's user avatar
  • 53
15 votes
2 answers
8k views

Can I use a primary constructor and also define a constructor body? Here is my attempt using a helper secondary constructor - I realize this is ambiguous, but I don't know if there is way to fix it... ...
quetzalcoatulus's user avatar
30 votes
4 answers
8k views

I am not so happy with primary constructors - because the constructor parameters are not readonly, it's too error prone in my opinion, especially when working with base classes which receive their own ...
me.at.coding's user avatar
  • 18.5k

15 30 50 per page