이 스타일 가이드는 SK Hynix systemic의 IT 운영/개발에 사용할 목적이며, Google/MS/Kakao/Naver 등 회사의 스타일을 참조하여 작성하였습니다.
명명 규칙은 Microsoft의 C# 명명 지침을 따릅니다 . Microsoft의 명명 지침이 지정되지 않은 경우(예: 개인 및 지역 변수) CoreFX C# 코딩 지침 에서 규칙을 가져옵니다.
규칙 요약:
PascalCase
.camelCase
._camelCase
.MyRPC
MyRpc
.I
로 시작합니다 (예: ) IInterface
.MyClass.cs
.public protected internal private new abstract virtual override sealed static readonly extern unsafe volatile async
.using
선언은 어떤 네임스페이스보다 맨 위에 옵니다. using
import 순서는 System
import 제외하고 알파벳순입니다.Google Java 스타일 참고
using System; // `using`은 네임스페이스 외부의 맨 위에 위치합니다.
namespace MyNamespace { // Namespaces = PascalCase.
// 네임스페이스 뒤에 들여쓰기.
public interface IMyInterface { // Interfaces start with 'I'
public int Calculate(float value, float exp); // Methods = PascalCase
// ...쉼표 뒤의 공백.
}
public enum MyEnum { // Enumerations = PascalCase.
Yes, // Enumerators = PascalCase.
No,
}
public class MyClass { // Classes = PascalCase.
public int Foo = 0; // Public member variables =
// PascalCase.
public bool NoCounting = false; // 필드 초기화를 권장합니다.
private class Results {
public int NumNegativeResults = 0;
public int NumPositiveResults = 0;
}
private Results _results; // Private member variables =
// _camelCase.
public static int NumTimesCalled = 0;
private const int _bar = 100; // const는 명명 규칙에 영향을 미치지 않습니다.
private int[] _someTable = { // 컨테이너 이니셜라이저는 2를 사용
2, 3, 4, // 공백 들여쓰기.
}
public MyClass() {
_results = new Results {
NumNegativeResults = 1, // 개체
초기화는 2칸 들여쓰기 사용
NumPositiveResults = 1,
};
}
public int CalculateValue(int mulNumber) { // 중괄호 열기
전에 줄 바꿈은 없음.
var resultValue = Foo * mulNumber; // 지역변수 = camelCase
NumTimesCalled++;
Foo += _bar;
if (!NoCounting) { // 단항 연산자 뒤에는 공백이 없고, ‘if‘ 뒤에 한칸 공백
if (resultValue < 0) { // option 문의
경우에도 중광호를 사용하고
// 비교연산자 주위에 공백을 둡니다.
_results.NumNegativeResults++;
} else if (resultValue > 0) { // 중괄호와 else 사이에 줄 바꿈이 없습니다.
_results.NumPositiveResults++;
}
}
return resultValue;
}
public void ExpressionBodies() {
//간단한 람다식의 경우 가능하면 한줄에 맞추고 대괄호, 중괼호는 필요하지 않습니다.
Func<int, int> increment = x => x + 1;
// 닫는 중괄호는 여는 중괄호를 포함하는 행의 첫번째 문자에 정렬 됩니다.
Func<int, int, long> difference1 = (x, y) => {
long diff = (long)x - y;
return diff >= 0 ? diff : -diff;
};
// 연속 줄바꿈 후에 정의 하는 경우 전체 본문을 들여쓰기 합니다.
Func<int, int, long> difference2 =
(x, y) => {
long diff = (long)x - y;
return diff >= 0 ? diff : -diff;
};
// 인라인 람다 인자도 이런 규칙을 따릅니다.
// 람다를 포함하는 경우 인자 그륩 앞에 산행 개행을 선호 합니다.
CallWithDelegate(
(x, y) => {
long diff = (long)x - y;
return diff >= 0 ? diff : -diff;
});
}
void DoNothing() {} // 빈 블락은 간결 할 수 있습니다.
// 가능하면 새 Line에 첫 번째 임수와 정렬 하여 다른 인자를 맞춥니다.
void AVeryLongFunctionNameThatCausesLineWrappingProblems(int longArgumentName,
int p1, int p2) {}
// 인자 라인을 첫 번째 인자와 정렬 하는 것이 적합 하지 않거나 읽기 어려운 경우
// 모든 인자를 새 줄에 4칸 들여쓰기오 묶습니다.
void AnotherLongFunctionNameThatCausesLineWrappingProblems(
int longArgumentName, int longArgumentName2, int longArgumentName3) {}
void CallingLongFunctionName() {
int veryLongArgumentName = 1234;
int shortArg = 1;
//가능하면 새 Line에 첫 번째 임수와 정렬 하여 다른 인자를 맞춥니다.
AnotherLongFunctionNameThatCausesLineWrappingProblems(shortArg, shortArg,
veryLongArgumentName);
//인자 라인을 첫 번째 인자와 정렬 하는 것이 적합 하지 않거나 읽기 어려운 경우
// 모든 인자를 새 줄에 4칸 들여쓰기오 묶습니다.
AnotherLongFunctionNameThatCausesLineWrappingProblems(
veryLongArgumentName, veryLongArgumentName, veryLongArgumentName);
}
}
}
다음 사항을 염두에 두고 최선의 판단을 내리세요.