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. Missing extension methods in 3.5 [modified]

Missing extension methods in 3.5 [modified]

Scheduled Pinned Locked Moved C#
helptutorialquestion
14 Posts 6 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
    Mark06
    wrote on last edited by
    #1

    Ive got a class library project set up, and its set for 3.5 framework.(Im actually following a tutorial online). However, when I reference a IList, I get no extension method in the list, such as ToArray. Im defining an object as:

    IList<int> results = new List<int>();
    // populate list

    var convertedtoArray = results.ToArray<int>();

    But I can compiler error because ToArray doesnt exist. Even though Im using the System.Collections.Generic namespace. Any ideas? Mark

    modified on Thursday, January 22, 2009 5:27 PM

    N E 2 Replies Last reply
    0
    • M Mark06

      Ive got a class library project set up, and its set for 3.5 framework.(Im actually following a tutorial online). However, when I reference a IList, I get no extension method in the list, such as ToArray. Im defining an object as:

      IList<int> results = new List<int>();
      // populate list

      var convertedtoArray = results.ToArray<int>();

      But I can compiler error because ToArray doesnt exist. Even though Im using the System.Collections.Generic namespace. Any ideas? Mark

      modified on Thursday, January 22, 2009 5:27 PM

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You must have a reference to the assembly in your project, not just a using statement.


      only two letters away from being an asset

      M 1 Reply Last reply
      0
      • N Not Active

        You must have a reference to the assembly in your project, not just a using statement.


        only two letters away from being an asset

        M Offline
        M Offline
        Mark06
        wrote on last edited by
        #3

        System.Collections.Generic sits in the System.Core assembly, which is referenced by default. :^)

        E 1 Reply Last reply
        0
        • M Mark06

          Ive got a class library project set up, and its set for 3.5 framework.(Im actually following a tutorial online). However, when I reference a IList, I get no extension method in the list, such as ToArray. Im defining an object as:

          IList<int> results = new List<int>();
          // populate list

          var convertedtoArray = results.ToArray<int>();

          But I can compiler error because ToArray doesnt exist. Even though Im using the System.Collections.Generic namespace. Any ideas? Mark

          modified on Thursday, January 22, 2009 5:27 PM

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          using System.Linq;

          and reference System.Core

          Eslam Afifi

          M P 2 Replies Last reply
          0
          • M Mark06

            System.Collections.Generic sits in the System.Core assembly, which is referenced by default. :^)

            E Offline
            E Offline
            Eslam Afifi
            wrote on last edited by
            #5

            No, only part of it. System.Collections.Generic.List<> is in mscorlib assembly, while System.Collections.Generic.Queue<> is in System assembly.

            Eslam Afifi

            1 Reply Last reply
            0
            • E Eslam Afifi

              using System.Linq;

              and reference System.Core

              Eslam Afifi

              M Offline
              M Offline
              Mark06
              wrote on last edited by
              #6

              using System.Linq, thats the one. Thanks Eslam!

              E 1 Reply Last reply
              0
              • M Mark06

                using System.Linq, thats the one. Thanks Eslam!

                E Offline
                E Offline
                Eslam Afifi
                wrote on last edited by
                #7

                You're welcome.

                Eslam Afifi

                1 Reply Last reply
                0
                • E Eslam Afifi

                  using System.Linq;

                  and reference System.Core

                  Eslam Afifi

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

                  Therein lies a great deal of what I don't like about extension methods.

                  N 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Therein lies a great deal of what I don't like about extension methods.

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #9

                    and what might that be?


                    only two letters away from being an asset

                    P 1 Reply Last reply
                    0
                    • N Not Active

                      and what might that be?


                      only two letters away from being an asset

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

                      People not knowing where they are and not even knowing that they are extension methods. At least as regular static methods it's clearer that the method is not part of the type. Exension methods are a form of obfuscation. But that's just me.

                      N 1 Reply Last reply
                      0
                      • P PIEBALDconsult

                        People not knowing where they are and not even knowing that they are extension methods. At least as regular static methods it's clearer that the method is not part of the type. Exension methods are a form of obfuscation. But that's just me.

                        N Offline
                        N Offline
                        N a v a n e e t h
                        wrote on last edited by
                        #11

                        PIEBALDconsult wrote:

                        even knowing that they are extension methods.

                        VS shows extension methods with a different icon in intellisense, right?

                        Navaneeth How to use google | Ask smart questions

                        P 1 Reply Last reply
                        0
                        • N N a v a n e e t h

                          PIEBALDconsult wrote:

                          even knowing that they are extension methods.

                          VS shows extension methods with a different icon in intellisense, right?

                          Navaneeth How to use google | Ask smart questions

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

                          Not everyone uses VS. Snippets of code posted here don't have intellisense either. Nor do printouts Don't rely on the behaviour of any one tool.

                          modified on Friday, January 23, 2009 1:26 AM

                          M 1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            Not everyone uses VS. Snippets of code posted here don't have intellisense either. Nor do printouts Don't rely on the behaviour of any one tool.

                            modified on Friday, January 23, 2009 1:26 AM

                            M Offline
                            M Offline
                            Mark Churchill
                            wrote on last edited by
                            #13

                            The semantics of an extension method are correct, and they increase code readability. They are certainly preferable than buggering up the type heirarchy with things like "MyListWithExtraStuff : List". They also allow you to extend any type which supports a particular interface, which is a powerful feature - almost like half-baked multiple inheritance. myFoo.Baz(bar); Is Baz an extension method? Does it matter? As long as it "bazzes" as documented, then it is no different from a normal method.

                            Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
                            Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.

                            P 1 Reply Last reply
                            0
                            • M Mark Churchill

                              The semantics of an extension method are correct, and they increase code readability. They are certainly preferable than buggering up the type heirarchy with things like "MyListWithExtraStuff : List". They also allow you to extend any type which supports a particular interface, which is a powerful feature - almost like half-baked multiple inheritance. myFoo.Baz(bar); Is Baz an extension method? Does it matter? As long as it "bazzes" as documented, then it is no different from a normal method.

                              Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
                              Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.

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

                              Mark Churchill wrote:

                              The semantics of an extension method are correct

                              Because they added those semantics.

                              Mark Churchill wrote:

                              they increase code readability

                              My opinion is that they do just the opposite.

                              Mark Churchill wrote:

                              any type which supports a particular interface

                              Just like regular static methods.

                              Mark Churchill wrote:

                              almost like half-baked multiple inheritance

                              You may be onto something there. Or maybe just on something. :-D

                              Mark Churchill wrote:

                              Does it matter?

                              Of course it makes a difference. Not to the original developer, not to the compiler, but when communicated between developers, particularly inexperienced ones. I'm well aware that I take the minority view on this and many other things, but I'm not the only one. Others [weasel words] have the same and other concerns. I do write an occasional extension method (see my recent "Untabify and Tabify"[^] article), but I try to make it clear that extension methods are in use.

                              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