31 lines
676 B
C#
31 lines
676 B
C#
using System;
|
|
|
|
namespace automatically_implemented_properties
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
// create a new Product object
|
|
Product myProduct = new Product();
|
|
|
|
// set the property value
|
|
myProduct.Name = "Kayak";
|
|
|
|
// get the property
|
|
string produtName = myProduct.Name;
|
|
Console.WriteLine("Product name: {0}", produtName);
|
|
}
|
|
}
|
|
|
|
public class Product
|
|
{
|
|
private string name;
|
|
|
|
public string Name
|
|
{
|
|
get { return name; }
|
|
set { name = value; }
|
|
}
|
|
}
|
|
} |