Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerics in c# & accessing the static members of T
    primarykey
    data
    text
    <p>My question concerns c# and how to access Static memebers ... Well I don't really know how to explain it (wich kind of is bad for a question isn't it?) I will just give you some sample code:</p> <pre><code>Class test&lt;T&gt;{ 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&lt;int&gt; (with type Integer) //I want my sample code to call int.TryParse(). If it were String //it should have been String.TryParse() } } </code></pre> <p>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!</p> <p>Thanks, Niklas</p> <hr> <p>Edit: Thank you all for your answers!</p> <p>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.</p> <p>This is why I chose the swich 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 :P )</p> <hr> <p>Though if you have some other suggestion I am still waiting (and willing to participate)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload