© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
arch_il

✅ Convert from string to Type?

public class Foo
{
  public string MyTypeInString = "Foo";
}

public static class SomeFunctions
{
  public static MyFunction<T>(T input)  
  {
    //
  }
}

public class Program
{
  public static void Main()
  {
    Foo f = new();
    SomeFunctions.MyFunction<f.MyTypeInString.ConvertToType()>(f);
  }
}
public class Foo
{
  public string MyTypeInString = "Foo";
}

public static class SomeFunctions
{
  public static MyFunction<T>(T input)  
  {
    //
  }
}

public class Program
{
  public static void Main()
  {
    Foo f = new();
    SomeFunctions.MyFunction<f.MyTypeInString.ConvertToType()>(f);
  }
}

How do I get that
ConvertToType(this string)
ConvertToType(this string)
function? I believe it should be possible.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

cannot convert from 'TypeA' to 'TypeB' with generics
C#CC# / help
2y ago
✅ Cannot convert from string[] to 'char' [SOLVED]
C#CC# / help
4y ago
✅ Convert Enum to string
C#CC# / help
4y ago
Cannot implicitly convert type 'System.Threading.Tasks.Task<string>' to 'string'
C#CC# / help
3y ago