在C#中切换的情况下 - 一个恒定值预期 [英] switch case in c# - a constant value is expected
本文介绍了在C#中切换的情况下 - 一个恒定值预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的code是如下:
public static void Output<T>(IEnumerable<T> dataSource) where T : class
{
dataSourceName = (typeof(T).Name);
switch (dataSourceName)
{
case (string)typeof(CustomerDetails).Name.ToString(); :
var t = 123;
break;
default:
Console.WriteLine("Test");
}
}
但是,这是不工作的情况下语句是给我一个错误说一个常数变量的预期。请帮家伙谢谢!
But this is not working the case statement is giving me a error saying that a constant variable is expected. Please help guys thank you!
推荐答案
基本上交换机已经不能评估的情况下声明语句。他们必须是静态评估。
Basically Switches cannot have evaluated statements in the case statement. They must be statically evaluated.
这篇关于在C#中切换的情况下 - 一个恒定值预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文