라벨이 C#인 게시물 표시

비주얼 스튜디오 유니코드로 저장하기

이미지
.editorconfig로 파일명으로 프로젝트 폴더 안에 저장한다. root = true [*] charset = utf-8 다음과 같이 저장한다.

C# 문자열 비교

if (strCompared.Equals(“문자열”)) { Console.WriteLine(“True”); }

C# 정규식

// 베이스 C# // 1.문자열에서 숫자만 남기기 & 문자만 남기기 --------------------------- // 참조추가 string tm = "a1b2c3d4"; string num = Regex.Replace(tm, @"\D", ""); // 숫자만 가져옴 // num 에는 1234 만 남는다.. string str = Regex.Replace(tm, @"[\d-]", string.Empty); // str 에는 abcd 만 남는다.

선택정렬

using UnityEngine; namespace Algorithm { public class Sort : MonoBehaviour { // Use this for initialization void Start() { ShowSelectSort(); } private static int[] SelectSort(int[] datas) { for (int i = 0; i datas[j]) { int temp = datas[j]; datas[j] = datas[i]; datas[i] = temp; } } } return datas; } private void ShowSelectSort() { int[] datas = new int[] { 83, 21, 13, 3, 13, 22, 53, 20, 2, 3, 7, 9 }; string before = "Before : "; string after = "After : "; for(int i = 0; i

try catch finally

try ~ catch 문은 예외를 처리하는 문법이다 문제는 try ~ catch 문이 '무엇인가'가 아니라 '언제' 사용하는가 인데 원래 try ~ catch 문은 수많은 에러체크 코드를 간편화하기위한 문법이다. 예를들어  FileInputStream 객체를 생성한다고 가정해보면 예외처리 없이는 파일을 열 때마다 조건을 검사해줘야한다. if(file1.isExist()){        fis1 = new FileInputStream(File1); }else{        System.out.println("File1 isn't exist"); } if(file2.isExist()){        fis2= new FileInputStream(File2) }else{        System.out.println("File2 isn't exist"); } if(file3.isExist()){        fis3= new FileInputStream(File3); }else{        System.out.println("File3 isn't exist"); } 하지만, 예외라는 것은 말그대로 예측할 수 없는 것인데. 확실하지도 않은 일로 일일히 검사코드를 작성하는 것은 불편하고, 소스코드의 가독성을 현저히 떨어뜨린다. 그래서 try ~ catch 문이 필요한것인데. 즉, 본래 try ~ catch의 목적은 '처음부터 일일히 신경쓰지말고, 따로 예외가 발생하면 처리하자' 라는 개념이다 . 위소스를 try catch로 변환한 예제 try{       fis1 = new File...

abstract class와 interface의 차이점rename

abstract clss는 보통 abstract 매소드를 가진 class 이며  객체를 생성 할 수 없다. abstract method 는 또 뭐란 말이냐?? abstract method는 모두 virtual 매소드 이며 하위  클래스에서 상속을 받는다면 반드시 구현해 주어야 하는 매소드 이다. virtual 매소드는?? 기반형의 매소드가 아닌 현재형의 매소드가 호출될 수 있도록 하는 키워드.. 그렇다면 이 둘의 차이는 무었일까. abstract class는 생성자를 가질수 있다. 그러나 interface는 그럴수 없다. abstract class는 abstract가 아닌 매소드를 가질수 있다. 그러나 interface는 그럴수 없다. abstract class는 맴버 변수를 가질 수 있다 .그러나 interface는 그럴수 없다. abstract class는 매소드의 접근자 모두를 가질수 있다. public, private, internal.. ect 그러나 iterface 는 public만 가질수 있다. abstract class는 클래스 이므로 하나만 상속이 가능하나. interface는 다중 상속이 가능하다. 그럼 언제 이 둘을 사용하여야 하는가?? 당연히.. is a 관게일땐 abstract class , 다른 연관이 없는 class에서 기능을 사용하고 싶을 경우는 interface는 사용하는 것이 좋겠다. exsample abstract    http://msdn.microsoft.com/ko-kr/library/sf985hc5(VS.80).aspx abstract class ShapesClass {     abstract public int Area(); } class Square : ShapesClass {     int x, y;     // Not providing an Area method results  ...