https://www.youtube.com/watch?v=3RNjm-5jYD4&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=65
using System;
using System.Collections.Generic;
using System.Text;
namespace testProject
{
public partial class Hello
{
public void Hi() => Console.WriteLine("FirstDeveloper.cs");
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace testProject
{
public partial class Hello
{
public void Bye() => Console.WriteLine("SecondDevleloper.cs");
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
// 이벤트 구독자(Subscriber)
class Program
{
static void Main(string[] args)
{
Hello hello = new Hello();
hello.Hi(); // FirsetDeveloper.cs
hello.Bye(); // SecondDeveloper.cs
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
class Point
{
// readonly 필드
public readonly int x;
public readonly int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public Point MoveBy(int dx, int dy)
{
return new Point(x + dx, y + dy);
}
}
class Program
{
static void Main(string[] args)
{
Point point = new Point(0, 0);
WriteLine(point.x);
WriteLine(point.y);
// WriteLine(point.x = 10);
// 메서드 체이닝
Point newPoint = point.MoveBy(100, 100).MoveBy(50, 50);
WriteLine(newPoint.x);
WriteLine(newPoint.y);
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
class Circle
{
public int Radius { get; private set; } = 0;
public Circle(int radius) => Radius = radius;
public Circle MakeNew(int radius) => new Circle(radius);
}
class Program
{
static void Main(string[] args)
{
// [1] 생성자를 통해서 반지름 10인 Circle 개체 생성
Circle circle = new Circle(10);
WriteLine($"Radius : {circle.Radius} - {circle.GetHashCode()}");
// [2] 메서드를 통해서 반지름 20인 Circle 개체 새롭게 생성
circle = circle.MakeNew(20);
WriteLine($"Radius : {circle.Radius} - {circle.GetHashCode()}");
}
}
}
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace testProject
{
class Car
{
public string Name { get; private set; }
public Car(string name) => Name = name;
// 생성자에게 재 전송
public static implicit operator Car(string name) => new Car(name);
}
class Program
{
static void Main(string[] args)
{
Car car1 = new Car("first Car");
WriteLine(car1.Name);
Car car2 = "Second Car";
WriteLine(car2.Name);
}
}
}