Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between public and private variables

namespace hi
{
    class hithere
    {
         public int numberOne = 12;
         private int numberTwo = 12;

         static void yo()
         {
         }
    }
}

Can someone tell me the difference between the variables numberOne and numberTwo in this code excerpt?

like image 812
DarkLightA Avatar asked May 03 '26 09:05

DarkLightA


1 Answers

From the accessibility levels at MSDN:

public Access is not restricted.

protected Access is limited to the containing class or types derived from the containing class.

internal Access is limited to the current assembly.

protected internal Access is limited to the current assembly or types derived from the containing class.

private Access is limited to the containing type.

like image 64
SDReyes Avatar answered May 05 '26 21:05

SDReyes