Csharp/C Sharp/Class Interface/private
Версия от 15:31, 26 мая 2010; (обсуждение)
MyClass class that contains a private courseName instance variable, and a property to get and set its value.
using System;
public class MyClass
{
private string courseName;
public string CourseName
{
get
{
return courseName;
}
set
{
courseName = value;
}
}
public void DisplayMessage()
{
Console.WriteLine( CourseName );
}
}
public class MyClassTest
{
public static void Main( string[] args )
{
MyClass myMyClass = new MyClass();
Console.WriteLine( "Initial course name is: "{0}"\n",myMyClass.CourseName );
Console.WriteLine( "Please enter the course name:" );
string theName = Console.ReadLine();
myMyClass.CourseName = theName;
Console.WriteLine();
myMyClass.DisplayMessage();
}
}