Skip to content

Instantly share code, notes, and snippets.

View nanwang2016's full-sized avatar
🏠
Working from home

Nan W nanwang2016

🏠
Working from home
View GitHub Profile
@nanwang2016
nanwang2016 / Private_Public_in_C#
Created July 18, 2020 17:38
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();
class Student
{
private string name; //Field
private string address; //Field
public string Name //Variable corresponds to Field "name"
{
get { return name; }
set { name = value; }
}
class Student
{
public string name { get; set;}
public string address {get; set;}
}
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student("Peter", "Home");
//Complier will issue an error say,
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student();
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student();
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student();
UniStudent.Name = "Jack";
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student("Jack", "007");
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student("Jack", "007");
Student NewUniStudent = new Student(UniStudent);
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
//Both Static and Default constructors will invoke for first instance
Student UniStudent = new Student();