String to TimeSpan InvalidCastException Case in C# dotnet core 6


String to TimeSpan InvalidCastException Case in C# dotnet core 6

다양한 타입의 문자열 데이터를 C#으로 파싱 하는 제네릭 한 함수를 개발하다가 독특한 상황이 생겨 기록해 둔다. //var timespanMinValue = "-10675199.02:48:05.4775808"; var timespanMinValue = TimeSpan.MinValue.ToString(); var ts1 = TimeSpan.Parse(timespanMinValue); var converter = TypeDescriptor.GetConverter(typeof(TimeSpan)); var ts2 = converter.ConvertFrom(timespanMinValue); var ts3 = Convert.ChangeType(timespanMinValue, typeof(TimeSpan)); 평범하게 문자열로 들어온 TimeSpan 값을 C#의 TimeSpan으로 Parse를 수행하는 코드인데 TimeSpan.Parse 가능 converter.ConvertFrom 가능 Conv...


#csharp #dotnet #dotnetcore #parse #timespan

원문링크 : String to TimeSpan InvalidCastException Case in C# dotnet core 6