✅ positional parameters

dose this sentence You can use positional parameters in a primary constructor to create and instantiate a type with immutable properties. form docs means that the record create a primary constractor that contains the parameter , or it means that i can create a primary constractor inside the record type with the parameter , as i read the record creates by default a primary constructor and a proparites that is inilized using this constractor
12 Replies
oke
oke5mo ago
huh
Anton
Anton5mo ago
I think it always creates a constructor with a parameter for each property, but you can create more regular constructors that call into it. But you should just look at the lowered code
Anton
Anton5mo ago
SharpLab
C#/VB/F# compiler playground.
Anton
Anton5mo ago
this thing allows you to view lowered code
steven preadly
steven preadlyOP5mo ago
I checked it on the sharplap ,it creates a constructor by default without need to create a new one that why I am asking ,the sentence above is not clear What's wrong
Anton
Anton5mo ago
just very broken English I had to reread it 5 times to understand but it's fine constructor* primary constructors is a new feature
class A(int param)
{
void f() => Console.WriteLine(param);
}
class A(int param)
{
void f() => Console.WriteLine(param);
}
this makes a constructor + a field for example on records that will make a public property instead of a field, always obviously you can't have two of these due to how the syntax is
steven preadly
steven preadlyOP5mo ago
Which sentence I get the sentence from the docs and I want to know what dose it mean think it's clear , on the other hand i am not here for my English evaluation I am here for technical question 😆 Let's get back to technical,traditional constructor can do all of this as before c#12 , I can create a ctor with parameters in c# before version 12, I don't see any different than traditional constructor
Anton
Anton5mo ago
It's just terser syntax It lowers to a regular constructor I don't care how good your English is. I just explained why they said "huh"
steven preadly
steven preadlyOP5mo ago
I am not a native English speaker 😆
Anton
Anton5mo ago
me neither
steven preadly
steven preadlyOP5mo ago
And maybe the one that says huh is not too 😆 Anyway, thank you very much for the explanation
Anton
Anton5mo ago
you're welcome
Want results from more Discord servers?
Add your server