help with my code it does not want to compile

This is a discussion on help with my code it does not want to compile within the C# Programming forums, part of the General Programming Boards category; Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericUse { class Gen<T,U> { public T t; public U ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    help with my code it does not want to compile

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    
    namespace GenericUse
    {
        class Gen<T,U>
        {
            public T t;
            public U u;
            
            public Gen(T _t, U _u)
            {
                t = _t;
                u = _u;
            }
            static void Main()
            {
                Gen<string, string> ao = new Gen<string, string>("Hello,", "World");
                Console.WriteLine(ao.t + ao.u);
            }
        }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    And your error messages are?

    Don't just dump the code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    sorry the error message is GenericUse.exe does not contain a static 'Main' method sui

    Quote Originally Posted by Salem View Post
    And your error messages are?

    Don't just dump the code.
    the error message is :GenericUse.exe does not contain a static 'Main' method suitable for an entry point

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    I would create a separate class for this:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    
    namespace GenericUse
    {
        class Gen<T,U>
        {
            public T t;
            public U u;
                
            public Gen(T _t, U _u)
            {
                t = _t;
                u = _u;
            }
        }
    
        public class Testing
        {
            static void Main()
            {
                Gen<string, string> ao = new Gen<string, string>("Hello,", "World");
                Console.WriteLine(ao.t + ao.u);
            }
        }
    }

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    thanks, that worked

  6. #6
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    To address *why* this was needed, it's because a generic class isn't really a single class - it's a family of related classes. Gen<int,string>.Main() is a different function from Gen<string, string>.Main() which is a different function than Gen<int,int>.Main(), etc.

    When you try to put the main method inside a generic, there isn't a way to know which specific class's Main() should be used as the entry point.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why won't this code compile??????
    By comp1911 in forum C Programming
    Replies: 15
    Last Post: 04-25-2010, 10:23 PM
  2. Code will not compile - code from a book!
    By Chubz in forum C++ Programming
    Replies: 19
    Last Post: 09-12-2004, 10:21 PM
  3. Replies: 3
    Last Post: 03-07-2003, 08:06 PM
  4. why won't this code compile?
    By vanilly in forum C Programming
    Replies: 9
    Last Post: 02-13-2003, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21