Access Modifiers
This lesson discusses access modifiers like public, private, protected and protected internal
We'll cover the following...
public
The public
keyword makes a class (including nested classes), property, method or field available to every consumer:
Press + to interact
using System;public class Dog{//these public attributes of class are available in other methods and classespublic string name = "lucy";public string gender = "female";public int age = 5;public int size = 5;public bool healthy = true;};class PublicExample{static void Main(){Dog dogObj = new Dog(); //making object of Dog class//the public members of class Dog can be accessed directly using dot operatorConsole.WriteLine("Doggo's name is: {0}",dogObj.name);Console.WriteLine("Doggo's gender is: {0}",dogObj.gender);Console.WriteLine("Doggo's age is: {0}",dogObj.age);Console.WriteLine("Doggo's size is: {0}",dogObj.size);Console.WriteLine("Is Doggo healthy? {0}",dogObj.healthy);}}
private
The ...