|
本文章是由機器翻譯。 將指標移到文章內的文字上方即可查看原文。 其他資訊。
|
譯文
原文
|
Expression.IfThenElse 方法
.NET Framework 4.5
命名空間: System.Linq.Expressions
組件: System.Core (在 System.Core.dll 中)
public static ConditionalExpression IfThenElse( Expression test, Expression ifTrue, Expression ifFalse )
參數
- test
- 型別:System.Linq.Expressions.Expression
要將 Test 屬性設定為與之相等的 Expression。
- ifTrue
- 型別:System.Linq.Expressions.Expression
要將 IfTrue 屬性設定為與之相等的 Expression。
- ifFalse
- 型別:System.Linq.Expressions.Expression
要將 IfFalse 屬性設定為與之相等的 Expression。
傳回值
型別:System.Linq.Expressions.ConditionalExpression// Add the following directive to the file: // using System.Linq.Expressions; bool test = true; // This expression represents the conditional block. Expression ifThenElseExpr = Expression.IfThenElse( Expression.Constant(test), Expression.Call( null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }), Expression.Constant("The condition is true.") ), Expression.Call( null, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }), Expression.Constant("The condition is false.") ) ); // The following statement first creates an expression tree, // then compiles it, and then runs it. Expression.Lambda<Action>(ifThenElseExpr).Compile()(); // This code example produces the following output: // // The condition is true.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (不支援伺服器核心角色), Windows Server 2008 R2 (SP1 (含) 以後版本支援伺服器核心角色,不支援 Itanium)
.NET Framework 並不支援各種平台的所有版本。如需支援的版本的清單,請參閱.NET Framework 系統需求。