블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

How do I get a Dictionary key by value in C#?

Dictionary<string, string> types = new Dictionary<string, string>()
{
    {"1", "one"},
    {"2", "two"},
    {"3", "three"}
};

 

 

[Answer]

Values do not necessarily have to be unique, so you have to do a lookup. You can do something like this:

var myKey = types.FirstOrDefault(x => x.Value == "one").Key;

If values are unique and are inserted less frequently than read, then create an inverse dictionary where values are keys and keys are values.

 

 

[출처] https://stackoverflow.com/questions/2444033/get-dictionary-key-by-value

 

Get dictionary key by value

How do I get a Dictionary key by value in C#? Dictionary<string, string> types = new Dictionary<string, string>() { {"1", "one"}, {"2", "two&q...

stackoverflow.com

 

[참조] https://miuna3.tistory.com/81

 

C# 사전 Dictionary의 Value 값으로 Key 찾기

Dictionary Dic = new Dictionary() { {"1", "Mon"}, {"2", "Tue"}, {"3", "Thu"} };사전이 위와같이 있다고 가정하자. 현재 Dic 의 키 "1" 은 값 "Mon"을 가지고있다. "Mon"으로 키 "1"을 찾고자 할 때에는 아래와 같이 사용하

miuna3.tistory.com

 

반응형
Posted by blueasa
, |

[에러 로그]

[Exception] ArgumentOutOfRangeException: Year, Month, and Day parameters describe 
            an un-representable DateTime.

----

 

개발을 하면서 연도와 상관없이 날짜(월/일/시/분/초) 비교를 위해 임의로 현재 날짜를 9999년으로 변환하게 해놨는데..

하필 오늘이 2024년 2월 29일 윤일(閏日)이다.

 

2024년 2월 29일에서 연도만 9999년으로 바꾸면서 new DateTime()을 하려니 위 에러가 발생했다.

잘 돌아가나 했던 로직이 윤일(閏日)에 에러가 남..(잘못만든거..)

 

해당 월(Month)에 해당 일(Day)이 있는지 체크하는 함수가 있으니 아래와 같이 체크해보고 처리하던가,

if (DateTime.DaysInMonth(2024,2) == 29)
    dt = new DateTime(2024, 2, 29);

 

아니면 다른 방식으로 처리를 해야 될 것 같다.

 

나의 경우는 연도를 같게 만들고 나머지를 비교하기 위해 무조건 9999년(임의 연도)으로 만들었는데..

에러가 나서 반대로 비교할 DateTime이 9999년이면 현재 연도(DateTime.Now.Year)에 맞추게 변경했다.

 

각자 원하는 방식으로 예외처리를 하면 될 것 같다.

 

[참조] https://stackoverflow.com/questions/11246563/year-month-and-day-parameters-describe-an-un-representable-datetime-exception

 

Year, Month, and Day parameters describe an un-representable DateTime Exception

I'm adding an object to a list within an ASP.NET MVC 3 application using the following code but one of the properties of the object is giving me difficulties. ls.Add(new UserRoleModel { UserRoleId...

stackoverflow.com

 

 

 

반응형
Posted by blueasa
, |

신호 유형


 

  • SIGABRT--프로그램 중단 명령 중단 신호
  • SIGALRM--프로그램 시간 초과 신호
  • SIGFPE--프로그램 부동 소수점 예외 신호
  • SIGILL--잘못된 프로그램 명령 신호
  • SIGHUP--프로그램 터미널 중단 신호
  • SIGINT--프로그램 키보드 인터럽트 신호
  • SIGKILL--프로그램이 종료되고 중단 신호를 받습니다.
  • SIGTERM--프로그램 종료 중단 신호
  • SIGSTOP--프로그램 키보드 중단 신호 
  • SIGSEGV--프로그램 잘못된 메모리 중단 신호
  • SIGBUS--프로그램 메모리 바이트 정렬 오류 중단 신호
  • SIGPIPE--프로그램 소켓이 중단 신호를 보내지 못했습니다.

 

[출처] https://www.cnblogs.com/daxiaxiaohao/p/4466097.html

 

[iOS]使用signal让app能够在从容崩溃 - Lewis.Xiaoa - 博客园

前言虽然大家都不愿意看到程序崩溃,但可能崩溃是每个应用必须面对的现实,既然崩溃已经发生,无法阻挡了,那我们就让它崩也崩得淡定点吧。iOS SDK中提供了一个现成的函数NSSetUncaughtExceptio

www.cnblogs.com

 

반응형
Posted by blueasa
, |

[링크] C# 특정 문자열 삭제, 특정 문자열 교체 Regex.Replace

 

C# 특정 문자열 삭제, 특정 문자열 교체 Regex.Replace

특정 문자열과, 삭제할 단어 혹은 문자가 주어졌을 때, 삭제하거나 교체하는 방법을 알아보도록 하자. 예시 Hello my world! 가 주어졌을 때, o와 y를 제외하고 출력하기 -> Hell m wrld! 기본적인 방법 : R

mentum.tistory.com

 

반응형
Posted by blueasa
, |

String Format for Int [C#]

Integer numbers can be formatted in .NET in many ways. You can use static method String.Format or instance method int.ToString. Following examples shows how to align numbers (with spaces or zeroes), how to format negative numbers or how to do custom formatting like phone numbers.

Add zeroes before number

To add zeroes before a number, use colon separator „:“and write as many zeroes as you want.

[C#]

String.Format("{0:00000}", 15);          // "00015"
String.Format("{0:00000}", -15);         // "-00015"

Align number to the right or left

To align number to the right, use comma „,“ followed by a number of characters. This alignment option must be before the colon separator.

[C#]

String.Format("{0,5}", 15);              // "   15"
String.Format("{0,-5}", 15);             // "15   "
String.Format("{0,5:000}", 15);          // "  015"
String.Format("{0,-5:000}", 15);         // "015  "

Different formatting for negative numbers and zero

You can have special format for negative numbers and zero. Usesemicolon separator „;“ to separate formatting to two or three sections. The second section is format for negative numbers, the third section is for zero.

[C#]

String.Format("{0:#;minus #}", 15);      // "15"
String.Format("{0:#;minus #}", -15);     // "minus 15"
String.Format("{0:#;minus #;zero}", 0);  // "zero"

Custom number formatting (e.g. phone number)

Numbers can be formatted also to any custom format, e.g. like phone numbers or serial numbers.

[C#]

String.Format("{0:+### ### ### ###}", 447900123456); // "+447 900 123 456"
String.Format("{0:##-####-####}", 8958712551);       // "89-5871-2551"

출처 http://www.csharp-examples.net/examples/
반응형
Posted by blueasa
, |

[링크] https://amiandappi.tistory.com/16

 

[C#][.NET framework] Directory.GetFiles() 로 여러 확장자 필터링 하기

지난번 포스팅에서 폴더 내 파일 목록을 가져오는 방법에 대해 공유 했다면 이번엔 복수개의 확장자로 필터링 하는 방법에 대해 포스팅 하려고 한다. var files = Directory.EnumerateFiles("C:\\path", "*.*", S

amiandappi.tistory.com

 

반응형
Posted by blueasa
, |

[링크] https://mirwebma.tistory.com/136

 

[C#/.Net][String To DateTime] 문자형을 Datetime형으로 변경하기

 Mir의 운영환경 본체 Intel Stick PC (STK2M3W64CC) O S Windows10 Home Application Micorsoft Visual Studio 2010 (10.0.30319.1) .Net Framework Ver 4.0 문자형을 DateTime형으로 변경하기 날짜와 시간의..

mirwebma.tistory.com

 

반응형
Posted by blueasa
, |

[링크]

https://afsdzvcx123.tistory.com/entry/C-%EB%AC%B8%EB%B2%95-C-%EB%AC%B8%EC%9E%90%EC%97%B4%EC%97%90%EC%84%9C-%EA%B3%B5%EB%B0%B1%EB%9D%84%EC%96%B4%EC%93%B0%EA%B8%B0-%EC%B2%B4%ED%81%AC%ED%99%95%EC%9D%B8-%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

 

[C# 문법] C# 문자열에서 공백(띄어쓰기) 체크(확인) 하는 방법

안녕하세요. 오늘은 C# 문법으로 문자열에서 공백, 띄어쓰기가 중간에 포함되어 있는지 확인하는 방법에 대해서 알려드리고자 합니다. 예제코드를 통하여 바로 알아볼게요!^^ 예제 코드 1 2 3 4 5 6

afsdzvcx123.tistory.com

 

반응형
Posted by blueasa
, |

[링크] https://developer-talk.tistory.com/326

 

[C#]List 특정 값 존재하는지 체크하는 방법

이번 포스팅은 C#의 List에서 특정 값이 존재하는지 체크하는 방법을 소개합니다. 목차 Contains() 함수 Exists() 함수 FindIndex() 함수 데이터 형식이 객체인 List Contains() 함수 Contains() 함수 구문은 다..

developer-talk.tistory.com

 

반응형
Posted by blueasa
, |

[링크] https://blog.naver.com/rookiemodel/10139446205

 

[ 스크랩 ] Regular Expression( 정규표현식 ) 총정리

1. 콤마( . ) . 는 어떤 문자 1개를 가리킨다. ( "줄바꿈 문자(\n)"는 제외) ============================...

blog.naver.com

 

반응형
Posted by blueasa
, |