29 questions
0
votes
0
answers
47
views
Constructor initializer issue - CS8862 [duplicate]
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 ...
0
votes
1
answer
63
views
How use with Primary constructor bodies?
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(...
0
votes
1
answer
207
views
Primary constructors in the Azure function
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 ...
0
votes
1
answer
131
views
Primary constructor and IDisposable
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 ...
0
votes
2
answers
296
views
What is the intended purpose of declaring a class without a body?
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 ...
10
votes
1
answer
6k
views
Warning in property initialization in class with primary constructor
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)
...
0
votes
1
answer
445
views
VS2022 Primary Constructor quick action not complete
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 ...
30
votes
4
answers
8k
views
Disable recommendation for primary constructors / IDE0290
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 ...
5
votes
1
answer
3k
views
CS9110: Cannot use primary constructor parameter that has ref-like type inside an instance member. But why not?
I'm updating my code to C# 12 and one aspect is to use primary constructors where it makes sense.
One place that's giving me a bit of a struggle is inside a ref struct which takes a ReadOnlySpan as a ...
30
votes
4
answers
6k
views
Null checking with primary constructor in C# 12
I using C# 12.
In C# 12 I can use primary constructor:
public class UserService(IUnitOfWork uow) : IUserService
{
}
Before C# 12 I used null checking for items that I inject in constructor:
public ...
2
votes
1
answer
759
views
Kotlin: How to use custom setters in primary constructor
I don't know how to make it so that when creating an object the values of the parameters "pass through the setters" the closest I've gotten is to duplicate the code, use once in the creation ...
1
vote
1
answer
132
views
How do I pass data from a variable into a constructor using the body of the variable?
I am trying to assign data to my class using the variable that I created. I want to use the variable as an instance of the membership class. Every time I pass any values I get an error.
error: no ...
3
votes
1
answer
260
views
How diamond problem in oops is solved using "shared" strategy?
Diamond problem is handled in some OOPS languages (eg. curl) by having the repeatedly inherited class as "shared"? I want to know how this works. Also, I want to know the role played by primary and ...
0
votes
1
answer
502
views
Kotlin primary and secondary constructors during inheritance
I am learning Kotlin and I'm kind of stuck with the constructors. I've written a program to help me understand the concept. The program is as follows:
open class Animal(){
var name :String = "...
11
votes
2
answers
2k
views
Moving away from primary constructors
The C# 6 preview for Visual Studio 2013 supported a primary constructors feature that the team has decided will not make it into the final release. Unfortunately, my team implemented over 200 classes ...