Snip2Code is shutting down.
It has been quite a ride, since 2013 when we launched our first prototype: thanks to the effort of you guys we collected more than 3 million snippets!
We are very proud to help all our users to be more efficient in their jobs, and to be the central point to share programming knowledge for everyone.
Our basic service is free, so we always survived on our own resources to give you Snip2Code.
Unfortunately, we are no more in the financial position to sustain this effort, and therefore we are announcing here our permanent shut down,
which will take place on August 1st, 2020.
Please save your private snippets using our backup function in the settings, here.
IF YOU WANT TO SAVE SNIP2CODE, PLEASE CONSIDER DOING A DONATION!
This will allow us to pay for the servers and the infrastructure. If you want to donate, Contact Us!
by
236 11
0
5
1,826
3
Top 1% !
Famous
Tagged
Refined
OpenSource
Popularity: 12462nd place

Published on:

Architecturex86_64
Extension.cs
LanguageCSharp
LicenseMIT_X11
OSWindows
Windows VersionWindows7

[CodingRule] HMS01

HMS 프로젝트 코딩 룰 01
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/450133/-CodingRule--HMS01?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { // 00 Inlitialize는 OnLoad 함수에서 처리 base.OnLoad(e); try { //00. Event 등록 전, 컨트롤 초기화 InitializeControl(); //00. Evnet 등록은 코드로 처리 InitializeEvent(); //01. if문 조건문에 ! 대신에 false로 처리하기 //02. 비교대상 문자열을 앞에 위치, Equals 함수 사용하기 CodingRule1(); //03. loop문 사용시 조건 확장메서드 사용하기 CodingRule2(); //04. validation 처리 CodingRule3(new DataTable()); } catch (Exception) { throw; } } #region Initialize private void InitializeControl() { try { } catch (Exception) { throw; } } private void InitializeEvent() { try { this.DoubleClick += new EventHandler(Form1_DoubleClick); this.button1.Click += new EventHandler(button1_Click); } catch (Exception) { throw; } } #endregion #region Event void Form1_DoubleClick(object sender, EventArgs e) { //01. Depth Level이 0인 함수는 꼭 Try Catch 문 처리할 것 try { testc(); } catch (Exception) { throw; } } private void testc() { //DETPTH 1 } void button1_Click(object sender, EventArgs e) { try { //01. sender를 형 변환해서 사용해야 재샤용성이 높아짐 if (sender is Button) { //02. as 로 캐스팅할 경우 캐스팅 실패시 null을 리턴함 //(Button) 식으로 캐스팅 할 경우 실패시 Exception 발생 Button btn = sender as Button; string str = btn.Name; } } catch (Exception) { throw; } } #endregion #region Method private void CodingRule1() { string tempStr = null; //tempStr의 값이 null일 경우에 false 값을 리턴함 //tempStr.Equals("Y") 처리했을 경우 Exceptiono 발생 if ("Y".Equals(tempStr) == false) { } } private void CodingRule2() { DataTable dt = new DataTable(); //불필요한 loop 제거 //람다식을 사용할 경우 디버그 모드에서 문제가 수정이 불하가하니 Select 함수 권장 foreach (DataRow row in dt.Select("ISUSABLE = 'Usable'")) { } } private void CodingRule3(DataTable dataTable) { // 분기문으로 Validation 처리하는 경우 조건을 부정문으로 작성하여 // 괄호로 감싸지 말고 Line 한줄로 처리할 것 (중복된 괄호처리로 인해 가독성이 낮아지는 현상 방지) if (dataTable == null || dataTable.Rows.Count <= 0) return; } #endregion }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus