Skip to content

Instantly share code, notes, and snippets.

@nanwang2016
Created July 22, 2020 13:18
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/b7648362775ad0f02de4c21d1949bc22 to your computer and use it in GitHub Desktop.
Save nanwang2016/b7648362775ad0f02de4c21d1949bc22 to your computer and use it in GitHub Desktop.
using System;
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
Student UniStudent = new Student();
UniStudent.Name = "Peter";
UniStudent.Address = "Home";
//Compiler will issue an error, as we attemp to read a set-only property
Console.WriteLine("Student's name is:" + UniStudent.Name);
}
}
class Student
{
private string name;
private string address;
public string Name
{
set
{
name = value;
}
}
public string Address
{
set
{
address = value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment