Csharp/C Sharp/Class Interface/private — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:39, 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();
}
}