更新 : 2007 年 11 月
エラー メッセージ
定数値が必要です。
定数を使用する必要がある箇所で変数を使用しました。詳細については、「switch (C# リファレンス)」を参照してください。
次の例では CS0150 エラーが生成されます。
// CS0150.cs
namespace MyNamespace
{
public class MyClass
{
public static void Main()
{
int i = 0;
int j = 0;
switch(i)
{
case j: // CS0150, j is a variable int, not a constant int
// try the following line instead
// case 1:
}
}
}
}
このエラーは、配列のサイズが変数値で指定されているときに、その配列が配列初期化子によって初期化された場合にも生成されます。このエラーを解決するには、別のステートメントで配列を初期化します。
// CS0150.cs
namespace MyNamespace
{
public class MyClass
{
public static void Main()
{
int size = 2;
double[] nums = new double[size] { 46.9, 89.4 }; //CS0150
// Try the following lines instead
// double[] nums = new double[size];
// nums[0] = 46.9;
// nums[1] = 89.4;
}
}
}