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. find function of List

find function of List

Scheduled Pinned Locked Moved C#
help
20 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.
  • S Sonia Gupta

    Problem is the following line of code. There is accuring an error. argument 1 cannot convert form annonymous method 1o predicate obj.Find(delegate(person p) { return p.age = 12; });

    Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #6

    I guessed that, it's just that, like always, you're guessing how the code should look instead of doing research, and making posts that don't give half way enough information to help people to help you. public class person { public string name; public int age; public person(string nam , int ag) { this.age = ag; this.name = nam; } } public class Program { public static void Main(string[] args) { List<person> obj = new List<person>(); obj.Add(new person("abc",22)); obj.Add(new person("ggbc1",12)); obj.Add(new person("ccc2",10)); obj.Add(new person("cabc3",12)); obj.Add(new person("bbbc4", 6)); Predicate<person> exists = delegate(person p1) { return p1.age == 12; }; person p = obj.Find(exists); } } } Note that find will only return one object, you can use FindAll to get a list back.

    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    1 Reply Last reply
    0
    • S Sonia Gupta

      Problem is the following line of code. There is accuring an error. argument 1 cannot convert form annonymous method to predicate obj.Find(delegate(person p) { return p.age = 12; });

      Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #7

      Sonia - I've already told you what the answer is. Read the full text above.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      1 Reply Last reply
      0
      • P Pete OHanlon

        Sonia - what error is the compiler returning? I'll give you a hint - you should use == not = in the check, but the compiler would have told you this. You have to learn how to interpret compiler errors rather than reaching for CodeProject as soon as you get an error you've not seen before. This and the error you posted below could both have been found with a little bit of effort and research on your part.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #8

        Mate, that was the least of her problems.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        1 Reply Last reply
        0
        • S Sonia Gupta

          Problem is the following line of code. There is accuring an error. argument 1 cannot convert form annonymous method to predicate obj.Find(delegate(person p) { return p.age = 12; });

          Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #9

          Sonia - I thought that I would see whether Google would have been able to answer your question. You know what? The first entry in the list matched your problem exactly. Why not try reaching for google rather than using us to help you compile your code? It'll help you become a better developer in the long run.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          S C 2 Replies Last reply
          0
          • P Pete OHanlon

            Sonia - I thought that I would see whether Google would have been able to answer your question. You know what? The first entry in the list matched your problem exactly. Why not try reaching for google rather than using us to help you compile your code? It'll help you become a better developer in the long run.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            S Offline
            S Offline
            Sonia Gupta
            wrote on last edited by
            #10

            can i use two filters in the find statement , according to there should not be two return statements in a single block. But i have to set two where conditions to refine the record.

            Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

            C P 2 Replies Last reply
            0
            • P Pete OHanlon

              Sonia - I thought that I would see whether Google would have been able to answer your question. You know what? The first entry in the list matched your problem exactly. Why not try reaching for google rather than using us to help you compile your code? It'll help you become a better developer in the long run.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #11

              You think this hasn't been said to her before ? She's lucky I got interested enough in the fact I didn't know the solution off the top of my head. And yes, I googled and the first hit told me exactly what to do, so I mocked up a sample for my own benefit as much as hers. I love the idea of anonymous predicates, but I don't find myself searching lists often enough to really use them.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              P 1 Reply Last reply
              0
              • S Sonia Gupta

                can i use two filters in the find statement , according to there should not be two return statements in a single block. But i have to set two where conditions to refine the record.

                Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #12

                Wow - you didn't listen to a thing he said, did you ? You have a function that returns bool. It's up to you, through the writing of actual code, to decide when that is true, or false. It can depend on as many different conditions as you like.

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                S 1 Reply Last reply
                0
                • C Christian Graus

                  Wow - you didn't listen to a thing he said, did you ? You have a function that returns bool. It's up to you, through the writing of actual code, to decide when that is true, or false. It can depend on as many different conditions as you like.

                  Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  S Offline
                  S Offline
                  Sonia Gupta
                  wrote on last edited by
                  #13

                  This time , i think u did not care to look the question carefully. the new question has nothing to do with the prior one.

                  Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                  C 1 Reply Last reply
                  0
                  • S Sonia Gupta

                    This time , i think u did not care to look the question carefully. the new question has nothing to do with the prior one.

                    Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #14

                    True - but it represents you ignoring what has been said to your countless times, not even thanking either of us for doing your job for you, and pressing on with the next thing you can't work out. I answered the question, didn't I ?

                    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    1 Reply Last reply
                    0
                    • P Pete OHanlon

                      Sonia - what error is the compiler returning? I'll give you a hint - you should use == not = in the check, but the compiler would have told you this. You have to learn how to interpret compiler errors rather than reaching for CodeProject as soon as you get an error you've not seen before. This and the error you posted below could both have been found with a little bit of effort and research on your part.

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      S Offline
                      S Offline
                      Sonia Gupta
                      wrote on last edited by
                      #15

                      Sorry Pete..... Thanks a Lot , :) For sorting out my problem.and one more thing , i am the luckiest one , for having discussion with the MVP Really :)Thanks a Lot

                      Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                      L 1 Reply Last reply
                      0
                      • S Sonia Gupta

                        Sorry Pete..... Thanks a Lot , :) For sorting out my problem.and one more thing , i am the luckiest one , for having discussion with the MVP Really :)Thanks a Lot

                        Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                        L Offline
                        L Offline
                        Laddie
                        wrote on last edited by
                        #16

                        It is not MVC it is MVP's :-D

                        Thanks Laddie Kindly rate if the answer was helpful

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          You think this hasn't been said to her before ? She's lucky I got interested enough in the fact I didn't know the solution off the top of my head. And yes, I googled and the first hit told me exactly what to do, so I mocked up a sample for my own benefit as much as hers. I love the idea of anonymous predicates, but I don't find myself searching lists often enough to really use them.

                          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #17

                          Christian Graus wrote:

                          You think this hasn't been said to her before ?

                          I know that we've both told her this many times. If I search through her history, I can find countless examples where she's been told to learn the basics. I can only hope that one day she might have the sense to think "Wait a second. These guys do know what they are talking about."

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          J 1 Reply Last reply
                          0
                          • S Sonia Gupta

                            can i use two filters in the find statement , according to there should not be two return statements in a single block. But i have to set two where conditions to refine the record.

                            Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #18

                            Why not try it? Rather than asking me to do your thinking for you, why not try it yourself. Honestly - it's as though you are being deliberately stupid.

                            Deja View - the feeling that you've seen this post before.

                            My blog | My articles

                            1 Reply Last reply
                            0
                            • P Pete OHanlon

                              Christian Graus wrote:

                              You think this hasn't been said to her before ?

                              I know that we've both told her this many times. If I search through her history, I can find countless examples where she's been told to learn the basics. I can only hope that one day she might have the sense to think "Wait a second. These guys do know what they are talking about."

                              Deja View - the feeling that you've seen this post before.

                              My blog | My articles

                              J Offline
                              J Offline
                              J4amieC
                              wrote on last edited by
                              #19

                              Pete O'Hanlon wrote:

                              I can only hope that one day she might have the sense to think

                              However, I think this goes in the same category as "I hope one day the israeli's and arabs might have the sense to think".

                              1 Reply Last reply
                              0
                              • C Christian Graus

                                and the problem is...... ???

                                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                                D Offline
                                D Offline
                                darkelv
                                wrote on last edited by
                                #20

                                Christian Graus wrote:

                                and the problem is...... ???

                                ... the missing of the ability to learn from past experience... even after 1100+ posts...

                                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