블로그 이미지
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-19 00:04

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
, |

[링크] 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
, |

[에러메시지]

NullReferenceException: Object reference not set to an instance of an object.

  at System.Linq.Expressions.Interpreter.LightLambda.MakeRunDelegateCtor (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Linq.Expressions.Interpreter.LightLambda.GetRunDelegateCtor (System.Type delegateType) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in <00000000000000000000000000000000>:0 

  at System.Linq.Expressions.Expression`1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Runtime.CompilerServices.CallSite`1[T].MakeUpdateDelegate () [0x00000] in <00000000000000000000000000000000>:0 

  at System.Runtime.CompilerServices.CallSite`1[T].GetUpdateDelegate (T& addr) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Runtime.CompilerServices.CallSite`1[T]..ctor (System.Runtime.CompilerServices.CallSiteBinder binder) [0x00000] in <00000000000000000000000000000000>:0 

  at System.Runtime.CompilerServices.CallSite`1[T].Create (System.Runtime.CompilerServices.CallSiteBinder binder) [0x00000] in <00000000000000000000000000000000>:0 

 

대충 위와같은 에러가 나는데..

유니티에서 dynamic을 쓰면 나는 에러인데..

결론은 유니티는 dynamic을 지원하지 않는다. 쓰지말자.

 

에디터에서는 잘되길래 될 줄 알았더만, 안드로이드 빌드해보니 위와같은 에러가 난다.

해결책이 별시리 없는듯하다.

 

[참조] https://gall.dcinside.com/mgallery/board/view/?id=game_dev&no=53076 

 

유니티 dynamic 못씀? - 인디 게임 개발 마이너 갤러리

분명 유니티 내에서 빌드 안하고 돌리면 잘만 돌아가는데, 빌드된 거 실행해보면 코드에서 에러가 계속 발생함NullReferenceException: Object reference not set to an instanc

gall.dcinside.com

[참조] https://issuetracker.unity3d.com/issues/il2cpp-notsupportedexceptions-exception-is-thrown-in-build-with-newtonsoft-dot-json-plugin

 

Unity IssueTracker - [IL2CPP] NotSupportedExceptions exception is thrown in build with Newtonsoft.Json plugin

Steps to reproduce: 1. Download attached project 2. Build standalone project on IL2CPP backend 3. Launch build project 4. Notice exc...

issuetracker.unity3d.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://vmpo.tistory.com/92

 

[C#] C# 에서 Mysql연동하기 (insert, select)

C#에서 Mysql DB를 연동하는 코드를 작성해 보도록 하겠습니다. Mysql설치가 필요하신 분들은, 아래 링크를 확인해주세요. https://vmpo.tistory.com/82 윈도우 10 Mysql 설치하기 (mysql 개발환경 세팅) 윈도우10

vmpo.tistory.com

 

반응형
Posted by blueasa
, |