The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 10 of 10

Thread: Generic Collection<t>

  1. #1

    Generic Collection<t>

    I am trying to compile a code using Collection, but Visual Express C# 2008 says that "type or namespace name 'Collection' could not be found."

    I am new to generics so I dont know what Im doing wrong.

    Code:
    Collection<string> people = new Collection<string>();
    That is the line that the compiler has trouble with.

  2. #2
    Im not 100% sure, (because I too am learning), but I dont think "Collection" is a valid class, let alone a valid generic class (Unless you wrote a class called Collection). Make sure you have the "System.Collections.Generic" reference, and you could use something like "List<>"..

    Code:
    List<string> people = new List<string>();
    Hope that helps.
    ~Dred

    Website: www.raydred.com
    My Comic: www.thatcomicthing.com
    Twitter: @Raydred http://www.twitter.com/raydred

  3. #3
    ^Learning is fun

    You forgot the namespace.
    Code:
    using System.Collections.ObjectModel;

    Join #kirupa | Click the under my Username | CL | Jeff

  4. #4
    Ah yes. Thank you. I thought I was supposed to add the System.Collections reference, but such thing did not exist.

  5. #5
    You should always have the

    Using System.Collections;

    But you would then add the other one below it.

    using System.Collections;
    using System.Collections.ObjectModel;

    Join #kirupa | Click the under my Username | CL | Jeff

  6. #6
    yay, i learned something as well!
    ~Dred

    Website: www.raydred.com
    My Comic: www.thatcomicthing.com
    Twitter: @Raydred http://www.twitter.com/raydred

  7. #7
    If you right-click on Collection, there should be a menu-item called Resolve that will take care of this for you automatically (unless the actual reference itself isn't there)

    Great, now even Kirupa is { facebooking | twittering }

  8. #8
    1,627
    posts
    hugeExplosions = true;
    Yeah usually it pops up with a squiggly line under the error and will pop up a suggestion box when you hover on this squiggly line usually giving you the namespaces with the most similar sounding items in with the one you want at the top.

    Of course if it already knows what you are talking about why does it need the imports statement ?!?!?!
    MS Paint FTW!


  9. #9
    ^I believe only vb.net does this.

    Join #kirupa | Click the under my Username | CL | Jeff

  10. #10
    1,627
    posts
    hugeExplosions = true;
    Oh, fair enough I program in .NET at work because noone knows C/C++ and they don't really want the headache of learning a new syntax so I've not really used c#

    Of course I do accidentally add braces and semicolons to the end of my .NET code sometimes
    MS Paint FTW!


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012