C#/Basics

· C#/Basics
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _05_Property { class Rect { /* public int Width { get; set; }*/ //prop 탭 두 번 >> 속성을 쓰는 것이 훨씬 간단하다. private int width; public int Width { get { return width; } set { if(width>=0) width = value; else Console.WriteLine("width는 0보다 커야합니다."); } } private int height; //proopful..
· C#/Basics
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _04_Constructor { class Date { public int year, month, day; //생성자 메소드 : 클래스와 이름이 같고 리턴값이 없는 메소드 >> 자동 호출(객체가 만들어질 때) public Date(int year, int month, int day) { this.year = year; //this.year은 public int year, month, day; 에 있는 year this.month = month; this.day = day; } pub..
· C#/Basics
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _03_staticMethod { class Program { class Date { public static bool IsLeap(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true; else return false; } } static void Main(string[] args) { //Date x = new Date(); Console.WriteLine("2021년은 윤년입니다 : {0..
· C#/Basics
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _02_FledNConst { class Product { public string name; public int price; } class Mymath { public static double PI = 3.14; //스태틱 필드 = 클래스 필드(값이 3.14로 초기화된) //객체.PI 가 아니라 Mymath.PI로 쓸 수 있음 } class MyCalendar { public const int months = 12; //const 상수로 됨 >> 바꿀 수 없음 public cons..
· C#/Basics
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _01_ClassNStruct { struct DateStruct //c#에서는 구조체 없어도 됨 class가 구조체랑 똑같기 때문에 { public int year, month, day; } class DateClasss { public int year, month, day; } class Program { static void Main(string[] args) { //65장 클래스와 구조체 DateStruct sDay; sDay.year = 2021; sDay.month = 4..
페프
'C#/Basics' 카테고리의 글 목록 (4 Page)