0
Please read description
https://code.sololearn.com/cjno6mQL8duc/?ref=app Okay it works fine but when I write public string Text { get; set; } It doesn't show anything.. Why??
16 ответов
+ 1
Oh okay, now I understand ...
* When we write ...
public string Text
{
get; set;
}
C# creates an auto property named `Text`, that reads and writes value from/to an auto member (created by C#), not the `text` member.
* When we write ...
public string Text
{
get { return text; }
set { text = value;}
}
C# reads and writes value from/to the private member `text`
I hope I get it right, cmiiw 👌
+ 3
Ok I read description 🙃🙃😂
+ 1
ShowPost() then should do Console.WriteLine(Text) instead of text for the argument.
+ 1
Ipang CarrieForle CarrieForle Why I need to write Text instead of text??
Why I don't need to write Text, when I manually mention that get accessor return text and set accessor, set value of text??
.... .... .... {get; set;} also automatically mention these things with the help of Compiler.. don't they??
Then why we need to write Text instead of text??
+ 1
Sorry I got disconnected.. I have re-edited my comment please read
+ 1
Samael,
I didn't get your comment, what you mean to ask actually? ...
Looks like connection issue again ...
+ 1
Ipang I did mean.. when we wrote
public string x {
get { ....}
set { ....}
}
we printed text
Then why we need to print Text instead of text
when we wrote
public string Text {get; set;}
+ 1
Ipang Then that means if we write
.... ... Text { get; set; }
There is a new variable named 'Text', isn't it?
if yes then why the compiler don't ask for two inputs??
One for text and another for Text??
+ 1
Ipang Thanks.. Sir.. That means Text is a variable now, isn't it?
+ 1
For more correct explanation about this auto implemented properties, please refer to
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties
https://www.tutorialsteacher.com/articles/set-default-value-to-property-in-csharp
+ 1
Giovanni EZINWA yeah brother.. please share your problem
0
You can also do this inside ShowPost()
Console.WriteLine( this.text );
0
You can access the `text` member directly by specifying `this` for context.
When we use `Text` as argument for `Console.WriteLine()`, we are accessing the `Text` property getter rather than accessing the `text` member directly.
0
Why should compiler ask for two inputs? at line 10 it reads one `string` input, at line 13 the input is fed in for `Text` property setter.
The private member `text` is never assigned any value when the auto property is used.
public string Text
{
get;
set;
}
0
✨Suchismita Behera✨ Thanks 🙂
0
Pls help me