SwitchCase Sınıf
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
bir büyük/küçük harf durumunu SwitchExpressiontemsil eder.
public ref class SwitchCase sealed
public sealed class SwitchCase
type SwitchCase = class
Public NotInheritable Class SwitchCase
- Devralma
-
SwitchCase
Aşağıdaki örnek, yöntemini kullanarak varsayılan bir durum olmadan switch deyimini temsil eden bir ifadenin SwitchCase nasıl oluşturulacağını gösterir.
// Add the following directive to the file:
// using System.Linq.Expressions;
// An expression that represents the switch value.
ConstantExpression switchValue = Expression.Constant(2);
// This expression represents a switch statement
// without a default case.
SwitchExpression switchExpr =
Expression.Switch(
switchValue,
new SwitchCase[] {
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("First")
),
Expression.Constant(1)
),
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Second")
),
Expression.Constant(2)
)
}
);
// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action>(switchExpr).Compile()();
// This code example produces the following output:
//
// Second
' Add the following directive to the file:
' Imports System.Linq.Expressions
' An expression that represents the switch value.
Dim switchValue As ConstantExpression = Expression.Constant(2)
' This expression represents a switch statement
' without a default case.
Dim switchExpr As SwitchExpression =
Expression.Switch(
switchValue,
New SwitchCase() {
Expression.SwitchCase(
Expression.Call(
Nothing,
GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
Expression.Constant("First")
),
Expression.Constant(1)
),
Expression.SwitchCase(
Expression.Call(
Nothing,
GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
Expression.Constant("Second")
),
Expression.Constant(2)
)
}
)
' The following statement first creates an expression tree,
' then compiles it, and then runs it.
Expression.Lambda(Of Action)(switchExpr).Compile()()
' This code example produces the following output:
'
' Second
Body |
Bu davanın gövdesini alır. |
Test |
Bu olayın değerlerini alır. Bu durum, bu değerlerden herhangi biri ile eşleştiğinde SwitchValue yürütme için seçilir. |
Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
Get |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
Get |
Type Geçerli örneğini alır. (Devralındığı yer: Object) |
Memberwise |
Geçerli Objectöğesinin sığ bir kopyasını oluşturur. (Devralındığı yer: Object) |
To |
|
Update(IEnumerable<Expression>, Expression) |
Bunun gibi, ancak sağlanan alt öğeleri kullanarak yeni bir ifade oluşturur. Tüm alt öğeler aynıysa bu ifadeyi döndürür. |
Ürün | Sürümler |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET geri bildirimi
.NET, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: