Home > Net >  Questions about the Predicate to entrust
Questions about the Predicate to entrust

Time:05-10

Predicate Commissioned in.net classes often appears in a class library, the entrusted are defined as follows:

Public delegatebool Predicate Obj (T);

From its definition as you can see, the delegate references a return a bool value method, in the actual development, usually use Predicate Entrust a variable reference a "judgment condition functions", in the judgment condition functions writing code that

Function parameters shall meet the conditions of the referenced object, condition is met, the function returns true.

I didn't understand: Predicate Delegate variable references a what kind of "judgment conditions function"? This "judgment conditions function" parameters can have? If you can, can have a few parameters.

CodePudding user response:


The most typical usage is List The Find (Predicate I believe you will match) method

CodePudding user response:

Predicate is actually very early, then in Linq era, actually use the generic Func Nature is replaced it,

"Statement" is a kind of input and output of the statement, if you want to tangle "its implementation code is what kind of?" This is putting the cart before the horse, you only according to the practical textbook to knock on a function code, and "will this function as a parameter to entrust the variable", what kind of, you just understand code is

The code is what kind of? You absolutely no more than their cognitive function,

CodePudding user response:

It is around but for your topic is very simple to entrust form CanYi shapes such as entrusted also said that only one parameter and returns a bool

Judging function do is simple just decided what kind of T satisfy conditions

CodePudding user response:

Consignment of the generic Predicate And Func ,
In fact, List . The Exists and List Use respectively. The First parameter is the two: Predicate And Func ,
Look from the function's signature, there is no difference, both of type T is to refer to, the return value is the function of bool, but after all both belong to different delegate type,

List The Entity. The First and the Entity. The Exists is used for condition judgment method,

CodePudding user response:

If you have the size of the Linq probability is no more Predicate, is actually at least 10 years earlier than Linq (VB) in the 90 s to Predicate in the entrust, and List<> In the early IEnumerable<> And so on before the advent of widely used what ForEach, All, Any packaging and so on function, after the egg came first the chicken, so we think All the chickens are born eggs,

CodePudding user response:

"Type declaration" is a very important concept, the compiler through it to check the bug, is there any design principle of a compilation system will more clearly understand the concept of compilation,

If on the importance of the build system is vague, even if that is the best "crisp heart will explain, chaos, universal, yuan" is a convenient programming language, then nature will not be able to understand why real high-level programming language should be the first to establish a set of Type specification,

Statement is like a contract, illustrates the behavior of the framework, that according to the specification should be "how to do", rather than with what is "inside",

CodePudding user response:

I want to say is: in the form in the application, the function "judgment conditions" that can accept parameters from the form controls?

CodePudding user response:

Predicate Entrust variable reference is a what kind of "judgment conditions function"? Know "judgment conditions function" returns a Boolean value of type, I don't know what can accept parameters (int, float, or string)?

CodePudding user response:

Said along while you don't know what is a generic???????????

CodePudding user response:


refer to 7th floor shijies response:
I want to say is: in the form in the application, the function "judgment conditions" that can accept parameters from the form controls?


So, we sometimes against don't say you want to do, just don't know from that post a noun problems

You so early, early someone back to you, please see the dynamiclinq

From the form the meaning of because of you, I can understand into a string a.x x> He is not a code, he is just a string, and type c # itself is static compilation, he does not support direct execution string

Want to become a code, you will need a lot of stuff, specific I also not much said, that I may not have a pile of glass heart said the ans bullying new

So simply give a don't need those specific principle, probably can achieve your requirements of dynamiclinq give you

CodePudding user response:

refer to the eighth floor shijies response:
Predicate Entrust variable reference is a what kind of "judgment conditions function"? Know "judgment conditions function" returns a Boolean value of type, I don't know what can accept parameters (int, float, or string)?


This foundation is very messy, you first make generic entity clear, to understand the generic delegate, and look at some instances demo, good understanding,
Why learn? Because the study List Or List At the same time, such as generic entity must grasp LINQ, Lambda expressions of usage,
When they study the expression, she will go deeper understanding. Any (), the FIrst () and Exists () method of application,

At this point, and then separate study commissioned by the generic principle, is easy to understand, don't put the question to abstract, this is not conducive to learning,

CodePudding user response:

Official reply now. I'm too lazy to give you find information

Literally baidu a certain garden written in this trifle

Var query=db. Customers
"Where (City==@ 0 and the Orders. Count & gt;=@ 1 ", "London", 10)
OrderBy (" CompanyName ")
Select (" new (CompanyName as Name, Phone) ");
You see, the where he wrote in the string,

Demand so you say, let me guess, that is, you let a person have a textbox input filter string, and then he can filter the,

Right, this thing can be limited to support this requirement (note that there is a limit to support, support him too complicated thing actually very laborious, do not directly on antlr4 SQL rules engine)
  •  Tags:  
  • C#
  • Related