Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 32709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:48:21+00:00 2026-05-10T13:48:21+00:00

My question concerns c# and how to access Static members … Well I don’t

  • 0

My question concerns c# and how to access Static members … Well I don’t really know how to explain it (which kind of is bad for a question isn’t it?) I will just give you some sample code:

Class test<T>{      int method1(Obj Parameter1){          //in here I want to do something which I would explain as          T.TryParse(Parameter1);           //my problem is that it does not work ... I get an error.          //just to explain: if I declare test<int> (with type Integer)          //I want my sample code to call int.TryParse(). If it were String          //it should have been String.TryParse()      } } 

So thank you guys for your answers (By the way the question is: how would I solve this problem without getting an error). This probably quite an easy question for you!


Edit: Thank you all for your answers!

Though I think the try – catch phrase is the most elegant, I know from my experience with vb that it can really be a bummer. I used it once and it took about 30 minutes to run a program, which later on only took 2 minutes to compute just because I avoided try – catch.

This is why I chose the switch statement as the best answer. It makes the code more complicated but on the other hand I imagine it to be relatively fast and relatively easy to read. (Though I still think there should be a more elegant way … maybe in the next language I learn)


Though if you have some other suggestion I am still waiting (and willing to participate)

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:48:22+00:00Added an answer on May 10, 2026 at 1:48 pm

    One more way to do it, this time some reflection in the mix:

    static class Parser {     public static bool TryParse<TType>( string str, out TType x )     {         // Get the type on that TryParse shall be called         Type objType = typeof( TType );          // Enumerate the methods of TType         foreach( MethodInfo mi in objType.GetMethods() )         {             if( mi.Name == 'TryParse' )             {                 // We found a TryParse method, check for the 2-parameter-signature                 ParameterInfo[] pi = mi.GetParameters();                 if( pi.Length == 2 ) // Find TryParse( String, TType )                 {                     // Build a parameter list for the call                     object[] paramList = new object[2] { str, default( TType ) };                      // Invoke the static method                     object ret = objType.InvokeMember( 'TryParse', BindingFlags.InvokeMethod, null, null, paramList );                      // Get the output value from the parameter list                     x = (TType)paramList[1];                     return (bool)ret;                 }             }         }          // Maybe we should throw an exception here, because we were unable to find the TryParse         // method; this is not just a unable-to-parse error.          x = default( TType );         return false;     } } 

    The next step would be trying to implement

    public static TRet CallStaticMethod<TRet>( object obj, string methodName, params object[] args ); 

    With full parameter type matching etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question says it all, really. My application is a time tracker. It's currently written
Question: Should I write my application to directly access a database Image Repository or
I'm implementing a small e-shop application in django. My question concerns modelling an Order
Based on my previous question here my new concern is how do I unit
What concerns, processes, and questions do you take into account when deciding when and
Question as stated in the title.
Question is pretty self explanitory. I want to do a simple find and replace,
Question Alright, I'm confused by all the buzzwords and press release bingo going on.
Question in the title. And what happens when all 3 of $_GET[foo] , $_POST[foo]
Question Can I build a image database/library that has an e-commerce style checkout system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.