public class Convention
{
}
public struct Convention
{
}
public interface IConvetion
{
}
public class Convetion
{
// 메서드.
public void ExMethod()
{
// 로컬 함수.
static void public ExFunc()
{
}
}
}
public void ExFunc(int exParemeter)
{
int numVal1;
int numVal2;
}
Console.WriteLine("한 줄에");
Console.WriteLine("하나씩");
int num1 = 1;
int num2 = 2;
static void Main(string[] args)
{
if (true)
{
Console.WriteLine("들여쓰기는 공백 4칸");
}
}
// 속성 정의와 메서드 정의 사이에 빈 줄을 하나 이상 추가.
// 속성 정의.
public Conventions Convention { get; set; }
// 메서드 정의.
public Conventions GetConvetino()
{
return this.Convention;
}
if ((val > val2) && (val1 > val3))
{
// 괄호를 사용하여 식의 절을 명확하게 구분.
}
// 별도의 줄에 주석을 배치.
public void ExFunc()
{
}
// English is applicable.
// 한글은 해당사항 없음.
public void ExFunc()
{
}
// 주석 텍스트 끝에는
// 마침표를 붙임.
//주석 (X)
// 주석 (O)
//*
//* 이처럼 서식이 지정된 별도 블록으로 주석을 묶지 않는다. *
//*
string name = $"{nameList[n].LastName}, {nameList[n].FirstName}";
var phrase = "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalala";
var manyPhrases = new StringBuilder();
for (var i = 0; i < 10000; i++)
{
manyPhrases.Append(phrase);
}
var var1 = "문자열";
var var2 = 10;
// 오해의 소지가 다분함
var inputInt = Console.ReadLine();
Console.WriteLine(inputInt);
var phrase = "lalalalalalalalalalalalalalalalalalalalalalalalalalalalalala"; var manyPhrases = new StringBuilder();
for (var i = 0; i < 10000; i++)
{
manyPhrases.Append(phrase);
}
// 명확한 형식을 사용
foreach (char ch in laugh)
{
if (ch == 'h')
Console.Write("H");
else
Console.Write(ch);
}
Console.WriteLine();
string[] vowels1 = { "a", "e", "i", "o", "u" };
var vowels2 = new string[] { "a", "e", "i", "o", "u" };
static string GetValueFromArray(string[] array, int index)
{
try
{
return array[index];
}
catch (System.IndexOutOfRangeException ex)
{
Console.WriteLine("Index is out of range: {0}", index);
throw;
}
}
Font font1 = new Font("Arial", 10.0f);
try
{
byte charset = font1.GdiCharSet;
}
finally
{
if (font1 != null)
{
((IDisposable)font1).Dispose();
}
}
// 위 코드와 동일한 코드.
using (Font font2 = new Font("Arial", 10.0f))
{
byte charset2 = font2.GdiCharSet;
}
Console.Write("배당금을 입력 : ");
int dividend = Convert.ToInt32(Console.ReadLine());
Console.Write("나누는 수 입력 : ");
int divisor = Convert.ToInt32(Console.ReadLine());
if ((divisor != 0) && (dividend / divisor > 0))
{
Console.WriteLine("Quotient: {0}", dividend / divisor);
}
else
{
Console.WriteLine("0으로 나누면 else");
}
var instance1 = new ExampleClass();
ExampleClass instance2 = new();
// 위와 같은 선언.
ExampleClass instance2 = new ExampleClass();
// 이니셜라이저 사용
var instance3 = new ExampleClass { Name = "Desktop", ID = 37414,
Location = "Redmond", Age = 2.3 };
// 이니셜라이저를 사용하지 않음
var instance4 = new ExampleClass();
instance4.Name = "Desktop";
instance4.ID = 37414;
instance4.Location = "Redmond";
instance4.Age = 2.3;
// 람다식 사용.
public Form2()
{
this.Click += (s, e) =>
{
MessageBox.Show(
((MouseEventArgs)e).Location.ToString());
};
}
// 람다식 사용하지 않음
public Form1()
{
this.Click += new EventHandler(Form1_Click);
}
void Form1_Click(object? sender, EventArgs e)
{
MessageBox.Show(((MouseEventArgs)e).Location.ToString());
}