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
Post a Comment