C# Code Snippets

Generic String Parsing

A string can be easily converted into a generic type with the TypeDescriptor class under the System.ComponentModel namespace.

Platform: .NET Framework 4.0

public static T As<T>(this string input)
    return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(input);



Back to C# Code Snippet List

Other C# Articles
Unable to connect to database! Please try again later.