c# 4.0 - Generic list and static main -


using system; using system.collections.generic; namespace consoleapplication74 { class program<t> {     public void add(t x)     {         console.writeline("{0}", x);     }     static void main(string[] args)     {                     program<string> mygeneric = new program<string>();         mygeneric.add("abc");         console.read();     } } 

i have erroe program not contain static 'main' method suitable entry point. program.cs properties has build action compile. have no idea wrong.

the main method, or entry point in program, cannot in class has generic arguments. program class has t type argument. c# specification calls out in section 3.1 under application startup:

the application entry point method may not in generic class declaration.

you should make new class instead of trying use program:

class program {     static void main(string[] args)     {                     myclass<string> mygeneric = new myclass<string>();         mygeneric.add("abc");         console.read();     } }  class myclass<t> {     public void add(t x)     {         console.writeline("{0}", x);     }    } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -