Only read,only write.

BrunoB

Well-known member
Joined
Nov 19, 2022
Messages
96
Programming Experience
Beginner
Hello, good morning, I'm reading the official documentation... to better understand read-only and write-only and I find this, but... where is the get? and the set? And if one is only read and write, why does it say as a comment that they are only getters? Thank you
1673710476856.png
 
Please provide links to the documentation you are referring to instead of screenshots.
 
I found where the the OP was reading from:

This has been a recurring theme with our OP. He seems to be reading too fast. It looks like he missed the previous paragraphs which said:
A property is declared like a field, except that the declaration ends with a get accessor or a set accessor written between the delimiters { and } instead of ending in a semicolon. A property that has both a get accessor and a set accessor is a read-write property. A property that has only a get accessor is a read-only property. A property that has only a set accessor is a write-only property.

and the text is the screenshot specifically says:
The following code is an example of use of these properties:

Anyway the relevant code that the OP is looking for is at:

Specifically:
C#:
public int Count => _count;

public int Capacity
{
    get =>  _items.Length;
    set
    {
        if (value < _count) value = _count;
        if (value != _items.Length)
        {
            T[] newItems = new T[value];
            Array.Copy(_items, 0, newItems, 0, _count);
            _items = newItems;
        }
    }
}
 
And if one is only read and write, why does it say as a comment that they are only getters?
Read more slowly. The first comment said "Invokes set accessor". The other two comments said "Invokes get accessor".

and the set?
The invocation of set calls lines 6-15 of post #5.

where is the get?
The first invocation of get calls line 1. The second invocation of get calls line 5.

And before you ask "but I don't see get. Where is it?", the expression bodied property:
C#:
public int Count => _count;
is just syntactic sugar for:
C#:
public int Count
{
    get
    {
        return _count;
    }
}

Notice that Count has only a getter. That is what makes it read-only.
 
He seems to be reading too fast.
Not just reading too fast but also not going back and rereading when something doesn't seem to make sense the first time.
 
Please provide links to the documentation you are referring to instead of screenshots.
I'm reading from the official documentation... to download it in pdf... but here they have sent me another pdf that has 3 thousand pages... the "c# tour" should be unified... I'm worried that they can edit it anytime person to this "official" or semi-official documentation.
I see that there are two different texts on properties, unfortunately I don't know how reliable this official documentation is.
the next time i will tka a link with screen bigger. thanks
 
Not just reading too fast but also not going back and rereading when something doesn't seem to make sense the first time.
Yes, you're right, a big problem is that when you want to learn about a specific topic, you have to read about 5 more topics and if you want to understand those 5, these in turn branch out into 5 more, or something like that... I think the official or semi-official documentation it is more detaianda to people ssr or something similar
 
the next time i will tka a link with screen bigger
Actually that makes things worse because now you are eating up my bandwidth quota on people who have to pay by the MB or GB on their mobile devices. Really, simply just send links to the documentation that you are referring to, and the put a short quote about the the specific text that is confusing you.
 
I think the official or semi-official documentation it is more detaianda to people ssr or something similar
The parts where MS has good documentation is often very detailed. The problem is that it is often too detailed to be used as a learning tool, but it is excellent for referring to when something doesn't quite behave as you would expect. Basically, imagine trying to learn C just by reading the *nix man pages. Yes, the man pages are accurate and detailed, but they often don't setup enough context to be able to learn. For some people who already know another programming language, and are more or less familiar with the programming paradigms used is OOP, then jumping straight into the MS documentation is often sufficient to be able to learn C#. But if you are still on the learning curve of learning C#, at the same time learning OOP, it can get overwhelming.

I highly recommend finding a book that is specifically written to teach C#. (I don't recommend learning C# from videos, unless that is truly your learning style.) Books have the advantage of letting you keep going back to review a paragraph or look at source code in detail.
 
Back
Top Bottom