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. a problem about "bool Exists(Predicate<T> match);"

a problem about "bool Exists(Predicate<T> match);"

Scheduled Pinned Locked Moved C#
csharpdotnetregexhelp
11 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.
  • W Offline
    W Offline
    wjp_auhtm
    wrote on last edited by
    #1

    I am trying to convert some code to .net framework 2.0 from .net framework 3.0. the code of .net framework 3.5 is:

    if (mItems.Exists(b => string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
    return;

    It can run in .net framework 3.5 and can not run in .net framework 2.0. Could someone tell me where the defferent things between 3.5 from 2.0 in the code are.

    D D 2 Replies Last reply
    0
    • W wjp_auhtm

      I am trying to convert some code to .net framework 2.0 from .net framework 3.0. the code of .net framework 3.5 is:

      if (mItems.Exists(b => string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
      return;

      It can run in .net framework 3.5 and can not run in .net framework 2.0. Could someone tell me where the defferent things between 3.5 from 2.0 in the code are.

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Lambda expressions were introduced in .Net 3.0. This should be enough:

      if (mItems.Exists(string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
      return;

      W L 2 Replies Last reply
      0
      • D dan sh

        Lambda expressions were introduced in .Net 3.0. This should be enough:

        if (mItems.Exists(string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
        return;

        W Offline
        W Offline
        wjp_auhtm
        wrote on last edited by
        #3

        Thanks! There is another problem. The parameter "b" whose type as same as parameter "item" is not defined. And the parameter "b" have not defined anywhere. I try to change the name of parameter "b" to "a",it also could run. I am puzzled about this.

        A D 2 Replies Last reply
        0
        • W wjp_auhtm

          Thanks! There is another problem. The parameter "b" whose type as same as parameter "item" is not defined. And the parameter "b" have not defined anywhere. I try to change the name of parameter "b" to "a",it also could run. I am puzzled about this.

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          "The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. " So b (and a) are your input parameters.

          Me, I'm dishonest. And a dishonest man you can always trust to be dishonest.
          Honestly. It's the honest ones you want to watch out for...

          W 1 Reply Last reply
          0
          • D dan sh

            Lambda expressions were introduced in .Net 3.0. This should be enough:

            if (mItems.Exists(string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
            return;

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            But you can use C# 3 with .NET 2.0

            W 1 Reply Last reply
            0
            • W wjp_auhtm

              Thanks! There is another problem. The parameter "b" whose type as same as parameter "item" is not defined. And the parameter "b" have not defined anywhere. I try to change the name of parameter "b" to "a",it also could run. I am puzzled about this.

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              That expression means that A variable "b" would be sent and the expression on the right side of "=>" would be executed on it. Now, you can see through your code and modify it accordingly. You can have a separate method that takes a variable of same type as "b" and returns the result or can declare the variable in the current method/class and use it. If you are using VS2008, you can set the target framework as 2.0 and the original code should work.

              W 1 Reply Last reply
              0
              • W wjp_auhtm

                I am trying to convert some code to .net framework 2.0 from .net framework 3.0. the code of .net framework 3.5 is:

                if (mItems.Exists(b => string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
                return;

                It can run in .net framework 3.5 and can not run in .net framework 2.0. Could someone tell me where the defferent things between 3.5 from 2.0 in the code are.

                D Offline
                D Offline
                Daniel Grunwald
                wrote on last edited by
                #7

                In that line of code, there shouldn't be any differences. Lambda expressions compile to the same IL as anonymous methods in C# 2.0; it shouldn't be the problem. The "Exists" method already was present for List<T> in .NET 2.0, so I don't see why your code would not run on .NET 2.0. Generally, if you use the C# 3.0 compiler without setting any references on .NET 3.x assemblies (e.g. System.Core), the resulting binary will run on .NET 2.0. What does "it can not run" mean? Do you get an exception? What is the error message?

                W 1 Reply Last reply
                0
                • D dan sh

                  That expression means that A variable "b" would be sent and the expression on the right side of "=>" would be executed on it. Now, you can see through your code and modify it accordingly. You can have a separate method that takes a variable of same type as "b" and returns the result or can declare the variable in the current method/class and use it. If you are using VS2008, you can set the target framework as 2.0 and the original code should work.

                  W Offline
                  W Offline
                  wjp_auhtm
                  wrote on last edited by
                  #8

                  Thanks! I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. Thank you.

                  1 Reply Last reply
                  0
                  • A Abhinav S

                    "The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. " So b (and a) are your input parameters.

                    Me, I'm dishonest. And a dishonest man you can always trust to be dishonest.
                    Honestly. It's the honest ones you want to watch out for...

                    W Offline
                    W Offline
                    wjp_auhtm
                    wrote on last edited by
                    #9

                    Thanks! I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. Thank you.

                    1 Reply Last reply
                    0
                    • L Lost User

                      But you can use C# 3 with .NET 2.0

                      W Offline
                      W Offline
                      wjp_auhtm
                      wrote on last edited by
                      #10

                      Yes, I can. I just want to konw why I could not debug the code successed in .net 2.0.

                      1 Reply Last reply
                      0
                      • D Daniel Grunwald

                        In that line of code, there shouldn't be any differences. Lambda expressions compile to the same IL as anonymous methods in C# 2.0; it shouldn't be the problem. The "Exists" method already was present for List<T> in .NET 2.0, so I don't see why your code would not run on .NET 2.0. Generally, if you use the C# 3.0 compiler without setting any references on .NET 3.x assemblies (e.g. System.Core), the resulting binary will run on .NET 2.0. What does "it can not run" mean? Do you get an exception? What is the error message?

                        W Offline
                        W Offline
                        wjp_auhtm
                        wrote on last edited by
                        #11

                        Thanks! I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. "it can not run", I said, means that, I could not debug the code in .net 2.0. And I just want to konw why it was happened. Thank you.

                        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