Talk about the difference between & and && in the judgment expression in the c#ienumerable<t> extension method?

Source: Internet
Author: User

Background

When working with frames in the process, I write the Code "T=>t.x.equals" (model) when I encounter the criteria for writing LINQ. ID) &t.y.equals (model. Name) "is similar to this form. But the results of the program error. Then I wrote the following code.

Code 1
1     class Program2     {3         Static voidMain (string[] args)4         {5             varPersons =getpersonlist ();6             varresult = persons. Where (U = u.age = =2&u.name=="B");7             foreach(varIteminchresult)8             {9 Console.WriteLine (item. ToString ());Ten             } One Console.readkey (); A         } -  -         Private StaticList<person>getpersonlist () the         { -             return NewList<person> -             { -                 Newperson {Name ="A", age =1}, +                 Newperson {Name ="B", age =2}, -                 Newperson {Name ="C", age =2} +             }; A         } at     } -  -      Public class Person -     { -          Public stringName {Get;Set; } -  in          Public intAge {Get;Set; } -  to          Public Override stringToString () +         { -             return string. Format ("Name:{0},age:{1}", Name, age); the         } *}

Run results

Code 2

1         Static voidMain (string[] args)2         {3             varPersons =getpersonlist ();4             varresult = persons. Where (U = u.age = =2&&u.name=="B");5             foreach(varIteminchresult)6             {7 Console.WriteLine (item. ToString ());8             }9 Console.readkey ();Ten}

In the original & Add a &, the same program can also run, the results are also

Questions

The ienumerable<t> extension method inside C # is the same as the bitwise operator (&) and the operator (&&)?

Talk about the difference between & and && in the judgment expression in the c#ienumerable<t> extension method?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.