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. What is the advantage of using IList over List in C# ?

What is the advantage of using IList over List in C# ?

Scheduled Pinned Locked Moved C#
questioncsharp
5 Posts 5 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
    md_azy
    wrote on last edited by
    #1

    Hi , What is the advantage of using IList over List in C# ? what is the difference between List and Ilist ? Thanks, Azeez

    0 D M P 4 Replies Last reply
    0
    • M md_azy

      Hi , What is the advantage of using IList over List in C# ? what is the difference between List and Ilist ? Thanks, Azeez

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      List implements IList. It takes the features of IList and implements them. Also, you can only actually create a List - IList is just a contract, or an Interface. So, List is better.

      OSDev :)

      1 Reply Last reply
      0
      • M md_azy

        Hi , What is the advantage of using IList over List in C# ? what is the difference between List and Ilist ? Thanks, Azeez

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        If you take a normal List<T> and call it's AsReadOnly method then it returns an IList<T> , so I assume an IList can be readonly whereas a List can't. I've never looked into it so I could be wrong... just an observation I made a couple of months ago and figured I'd investigate one day!

        Dave
        Generic BackgroundWorker - My latest article!
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        1 Reply Last reply
        0
        • M md_azy

          Hi , What is the advantage of using IList over List in C# ? what is the difference between List and Ilist ? Thanks, Azeez

          M Offline
          M Offline
          Mirko1980
          wrote on last edited by
          #4

          IList is an interface from which all lists derive from. So, while List is an IList, the opposite is not true. If you need a normal list, use the List class, if you need to build your own list with custom behavior (such as read only, for example), derive from IList. If you want your method to accept as parameter different type of list from the standard one, use IList as parameter type. If you want to hide the specific list type your method is returning, use IList as return type.

          1 Reply Last reply
          0
          • M md_azy

            Hi , What is the advantage of using IList over List in C# ? what is the difference between List and Ilist ? Thanks, Azeez

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Flexibility. A method that accepts a List can only accept a List (or something derived from List), whereas a method that accepts an IList can accept anything that implements IList, not just List.

            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