The .NET Framework has the Convert.ChangeType Method which converts the object specified to the conversion type. The value should implement the IConvertible interface for the conversion to be successful.
Convert.ChangeType Method in C#
Below is a simple code snippet demonstrating Convert.ChangeType Method in C#
using System; namespace AbundantCode { internal class Program { // Convert.ChangeType Method in C# private static void Main(string[] args) { string input = "true"; bool Output = (bool)Convert.ChangeType(input, typeof(bool)); Console.WriteLine(Output.ToString()); Console.ReadLine(); } } }
1 Comment