Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Id and its Details

Id and its Details

Scheduled Pinned Locked Moved C#
questioncsharp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeyyy
    wrote on last edited by
    #1

    First time to pose a question on this board...fairly new to C# too, so please go easy :-D I want to do something like this in Generics:

    List myList = new List();

    This blows up obviously...any workarounds? Thanks! Mikeyyy

    M T 3 Replies Last reply
    0
    • M Mikeyyy

      First time to pose a question on this board...fairly new to C# too, so please go easy :-D I want to do something like this in Generics:

      List myList = new List();

      This blows up obviously...any workarounds? Thanks! Mikeyyy

      M Offline
      M Offline
      Mikeyyy
      wrote on last edited by
      #2

      I don't know why, but half of the syntax didn't show: List myList = new List();

      T M C 3 Replies Last reply
      0
      • M Mikeyyy

        First time to pose a question on this board...fairly new to C# too, so please go easy :-D I want to do something like this in Generics:

        List myList = new List();

        This blows up obviously...any workarounds? Thanks! Mikeyyy

        T Offline
        T Offline
        Tarakeshwar Reddy
        wrote on last edited by
        #3

        Thats because it's expecting T which is the type of element in the list. If your creating a list of strings then you should declare it as List<string> myList = new List<string>();

        1 Reply Last reply
        0
        • M Mikeyyy

          I don't know why, but half of the syntax didn't show: List myList = new List();

          T Offline
          T Offline
          Tarakeshwar Reddy
          wrote on last edited by
          #4

          Ignore my other reply, I assumed you didn't pass the type of element, the html formatting actually removed it. The list can have only one type, so it would be List<string> myList = new List<string>(); or List<int> myList = new List<int>(); If your are looking at having a KeyedList then have a look at this article[^]

          1 Reply Last reply
          0
          • M Mikeyyy

            I don't know why, but half of the syntax didn't show: List myList = new List();

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Hello, Maybe Dictonary is what you are looking for.

            using System.Collections.Generic;
            Dictionary openWith = new Dictionary();

            http://msdn2.microsoft.com/en-us/library/xfhwa508.aspx[^] Hope it helps! All the best, Martin

            1 Reply Last reply
            0
            • M Mikeyyy

              I don't know why, but half of the syntax didn't show: List myList = new List();

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              If you are trying to store two items for each element in the list then you should be creating a class.

              class DtoListItem
              {
              public int SomeInt;
              public string[] SomeStringArray;
              }

              // In some method somewhere...
              List<DtoListItem> myList = new List<DtoListItem>();


              Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              1 Reply Last reply
              0
              • M Mikeyyy

                First time to pose a question on this board...fairly new to C# too, so please go easy :-D I want to do something like this in Generics:

                List myList = new List();

                This blows up obviously...any workarounds? Thanks! Mikeyyy

                M Offline
                M Offline
                Mikeyyy
                wrote on last edited by
                #7

                Mikeyyy

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups