5.1.1 Using Automatically Implemented Properties: Defining a property and consume it
This commit is contained in:
parent
cb7c1f22a5
commit
ddbaeaa84f
@ -0,0 +1,31 @@
|
|||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "automatically_implemented_properties", "automatically_implemented_properties\automatically_implemented_properties.csproj", "{96E49340-18A4-48F0-A71F-D756FFFC27A5}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{96E49340-18A4-48F0-A71F-D756FFFC27A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{96E49340-18A4-48F0-A71F-D756FFFC27A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{96E49340-18A4-48F0-A71F-D756FFFC27A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{96E49340-18A4-48F0-A71F-D756FFFC27A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
Loading…
x
Reference in New Issue
Block a user