P.minji
P.minji

Reputation: 43

c# access modifier section like c++

Do I need to write all access modifiers in c#?

static class Node {
    Node link;//Node * link;
    int data;

    public:
        void setlink(Node next){...}
        void display(){.....}

I want to use access modifiers section(public:, protected:)like in c++ how can I use it?
Do I have to write all of them?

public void setlink(Node next){...}
public void display(){...}

instead

public:
    void setlink(Node next){....}
    void display(){....}

Upvotes: 3

Views: 415

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502466

Yes, you specify it on each member. Two good things about this:

  • Moving the methods around within the same class can't affect anything.
  • You can immediately see the access modifier by looking at the method declaration. No need to look higher up in the file to see if you're in a public section or not.

Upvotes: 6

Related Questions