Skip to content

Instantly share code, notes, and snippets.

@nanwang2016
Created July 18, 2020 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanwang2016/9ab84b87f8c5e43419ae0bfebce6db6b to your computer and use it in GitHub Desktop.
Save nanwang2016/9ab84b87f8c5e43419ae0bfebce6db6b to your computer and use it in GitHub Desktop.
Demonstration of Private and Public Access Specifier in C#
using System;
namespace Private_Public
{
class Program
{
static void Main(string[] args)
{
Calculator Plus = new Calculator();
Plus.Acceptdetails();
Plus.Display();
Console.ReadLine();
}
}
class Calculator
{
//member variables
private double a;
private double b;
public void Acceptdetails()
{
Console.WriteLine("Enter a: ");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter b: ");
b = Convert.ToDouble(Console.ReadLine());
}
public double Plus()
{
return a+b;
}
public void Display()
{
Console.WriteLine("a: {0}", a);
Console.WriteLine("b: {0}", b);
Console.WriteLine("total: {0}", Plus());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment