/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/programming-guide/classes-and-structs/snippets/partial-classes-and-methods/Program.cs
184 строки
3 KB
Bill Wagner
Update documents for `field` backed properties (#43261)
13 ноя 2024, 14:41
Не верифицирован
13 ноя 2024, 14:41
8aeac83
Код
Авторство
О чём код?
//<Snippet1> // This is in Employee_Part1.cs public partial class Employee { public void DoWork() { } } // This is in Employee_Part2.cs public partial class Employee { public void GoToLunch() { } } //Main program demonstrating the Employee class usage public class Program { public static void Main() { Employee emp = new Employee(); emp.DoWork(); emp.GoToLunch(); } } // Expected Output: // Employee is working. // Employee is at lunch. //</Snippet1> //<Snippet2> class Container { partial class Nested { void Test() { } } partial class Nested { void Test2() { } } } //</Snippet2> namespace MoonExample.Partial { //<Snippet3> [SerializableAttribute] partial class Moon { } [ObsoleteAttribute] partial class Moon { } //</Snippet3> } namespace MoonExample.NonPartial { //<Snippet4> [SerializableAttribute] [ObsoleteAttribute] class Moon { } //</Snippet4> } class Planet { } interface IRotate { } interface IRevolve { } //<Snippet5> partial class Earth : Planet, IRotate { } partial class Earth : IRevolve { } //</Snippet5> class WrapEquivs { //<Snippet6> class Earth : Planet, IRotate, IRevolve { } //</Snippet6> } //<Snippet7> public partial class A { } //public class A { } // Error, must also be marked partial //</Snippet7> //<Snippet8> partial class ClassWithNestedClass { partial class NestedClass { } } partial class ClassWithNestedClass { partial class NestedClass { } } //</Snippet8> namespace WrapCoords2 { //<Snippet9> // This is in Coords_Part1.cs public partial class Coords { private int x; private int y; public Coords(int x, int y) { this.x = x; this.y = y; } } // This is in Coords_Part2.cs public partial class Coords { public void PrintCoords() { Console.WriteLine("Coords: {0},{1}", x, y); } } // Main program demonstrating the Coords class usage class TestCoords { static void Main() { Coords myCoords = new Coords(10, 15); myCoords.PrintCoords(); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } // Output: Coords: 10,15 //</Snippet9> } //<Snippet10> partial interface ITest { void Interface_Test(); } partial interface ITest { void Interface_Test2(); } partial struct S1 { void Struct_Test() { } } partial struct S1 { void Struct_Test2() { } } //</Snippet10> // <FieldProperty> // in file1.cs public partial class PropertyBag { // Defining declaration public partial int MyProperty { get; set; } } // In file2.cs public partial class PropertyBag { // Defining declaration public partial int MyProperty { get => field; set; } } // </FieldProperty>