Programming/C#

Programming/C#

C# var형 사용 예제

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using System; namespace Property { class MainApp { static void Main(string[] args) { var a = new { Name = "가변형", Age = 123 }; Console.WriteLine("Name : {0}, Age : {1}", a.Name, a.Age); var b = new { Subject = "영어", Scores = new int[] {10, 11, 12, 13, 14}}; foreach (var score in b.Scores) Console.Write("{0} ", score); Console.WriteLine(); } } }

Programming/C#

Property 사용예제

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 using System; namespace Birth { class BirthDayInfo { public string Name { get; set; } public DateTime Birthday { get; set; } public int Age { get { return new DateTime(DateTime.Now.Subtract(Birthday).Ticks).Year; } } } class Myapp { static void Main(string[] args){ BirthDayInfo birth = new BirthDay..

Programming/C#

인터페이스 property (Interface property)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 using System; namespace Property { interface INamedValue { string Name { get; set; } } class NamedValue : INamedValue { public string Name { get; set; } public string Value { get; set; } } class MainApp { static void Main(string[] args) { NamedValue name = new NamedValue(..

Programming/C#

추상클래스 property (abstract class property)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 using System; namespace Property { abstract class Product { private static int serial = 0; public string SerialID { get { return String.Format("{0:d5}", serial++); } } abstract public DateTime ProductDate { get; set; } } class MyProduct : Product { public override DateTime ProductDat..

후유증
'Programming/C#' 카테고리의 글 목록