Home > Net >  How can expression, passed as a parameter
How can expression, passed as a parameter

Time:11-18

In c #, can expression, passed as a parameter?

In the following method, for example, if the expression of actual can be very complex, changeable, need to change according to the content of the key value, should be how to deal with right now? Thank you
 private void Test () 
{
DataGridView. Rows. The Clear ();
Foreach (var name in dic. Keys)
{
If (name. StartsWith (" Final ") | | name. StartsWith (" Sub "))//here should be how to design to satisfy different needs?
{
Int rowIndex=dataGridView. Rows. The Add ();
Foreach (DataGridViewColumn column in dataGridView. Columns)
{
DataGridViewCell currentCell=dataGridView. Rows [rowIndex] Cells [column. The Index];
CurrentCell. Value=https://bbs.csdn.net/topics/dic [name];
}
}
}
}

CodePudding user response:

The test ( func Func
{
DataGridView. Rows. The Clear ();
Foreach (var name in dic. Keys)
{
If ( func (name))//here should be how to design to satisfy different needs?
{
Int rowIndex=dataGridView. Rows. The Add ();
Foreach (DataGridViewColumn column in dataGridView. Columns)
{
DataGridViewCell currentCell=dataGridView. Rows [rowIndex] Cells [column. The Index];
CurrentCell. Value=https://bbs.csdn.net/topics/dic [name];
}
}
}
}

Simple demonstration, of course I didn't judge whether he is null, here yourself

CodePudding user response:

Learn express Or the func (), action (), etc.
Express Build the expression tree,
Common memory directly manipulate data, can use the func

The following figure illustrates the,
1 set Func
the condition of2 myList invokes the where clause, add 1
the condition of

CodePudding user response:

refer to the second floor is nu month god reply:
learn express Or the func (), action (), etc.
Express Build the expression tree,
Common memory directly manipulate data, can use the func

The following figure illustrates the,
1 set Func
the condition of2 myList invokes the where clause, add 1
the condition of

Method is very good, if you say your complex, please on design patterns, I do not believe you,,,,,,,

CodePudding user response:

In fact 99.99% of the actual project cases, "reverse" is not required to consider what "universal solution", but to provide a rapid development tools,

You write a programmer who can understand the "intention" of the program, as long as there is idea, programmers in the brain a program to write the code, and test reports are printed out, great not great? Don't fake fake? Utility is not practical?

CodePudding user response:

You can use func<> Delegate or expression Expression trees

CodePudding user response:

In fact, most programmers, 80% of the time in time, to do all sorts of false "research and development," of course this is reality, assuming that most programmers can get 80% of the time to do the right thing, so there is no programming industry, fool, also no one can rely on to hire a programmer to make money,

CodePudding user response:

Risk as a manager is clear, there are some things only make technology "thought" is cool, the real practitioners see big trend to figure out whether something someone can determine the consideration, can see cannot guarantee a compile-time error, testing found that as many as possible logic errors, don't wait for the future system online then because of the so-called "universal hidden error" a problem in front of the user,

CodePudding user response:

reference mingcsharp reply: 3/f
Quote: refer to the second floor is nu month god reply:

Learn express Or the func (), action (), etc.
Express Build the expression tree,
Common memory directly manipulate data, can use the func

The following figure illustrates the,
1 set Func
the condition of2 myList invokes the where clause, add 1
the condition of

Method is very good, if you say your complex, please on design patterns, I do not believe you,,,,,,,

CodePudding user response:

Upstairs is a great god, the following code line 19 compile error:

 class AttributeTag 
{
Public Expression Bool> The Filter {get; The set; }
//...
}

The class JobInfo
{
Public static Dictionary> AllAttrs {get; The set; }
//...
}


Private void Test ()
{
Var dic.=the JobInfo AllAttrs [InterfaceType PROCESS];
AttributeTag=new attributeTag
{
The Filter=dic. The Where (d=& gt; D.K ey. StartsWith (" Final ") | | d.K ey. StartsWith (" Sub ") | | d.K ey. StartsWith (" Buired ")),
InterfaceType=InterfaceType. PROCESS
};
DgvResinPlug. Tag=attributeTag;
}


Prompt error 19, could you tell me how to modify:
Cannot type
"System. Collections. Generic. IEnumerable & gt;"
An implicit conversion to
"System. Linq Expressions. Expression Bool> & gt;"

CodePudding user response:

reference 1st floor wanghui0380 response:
test ( func Func
{
DataGridView. Rows. The Clear ();
Foreach (var name in dic. Keys)
{
If ( func (name))//here should be how to design to satisfy different needs?
{
Int rowIndex=dataGridView. Rows. The Add ();
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related