在IF条件声明VAR错误中的C#cosole app错误 [英] C# cosole app ERROR in IF CONDITION DECLARING VAR ERROR
本文介绍了在IF条件声明VAR错误中的C#cosole app错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
命名空间 ConsoleApplication3
{
class 计划
{
public static void Main( string [] args)
{
int chess = 8 ;
string dark = x跨度>;
string light = y跨度>;
for ( var line1 = 0 ; line1 < chess; line1 ++);
{
for ( var coloumn2 = 0 ; coloumn2 < chess; coloumn2 ++);
{
string 结果;
if (LINE == 0 )
{
}
}
}
}}}
我尝试了什么:
我只是想知道这个LINE1 VAR如果条件怎么做我是新来的C#SORRY for SILLY QUESTION
解决方案
不要使用var - 使用实际的变量类型。在这种情况下,这不是导致问题的原因,而是你的帽子钥匙坏了,你有假的分号!
试试这个:
public static void Main( string [] args)
{
int 国际象棋= 8 ;
string dark = x跨度>;
string light = y跨度>;
for ( var line1 = 0 ; line1 < chess; line1 ++)
{
for (< span class =code-keyword> var column2 = 0 ; column2 < 国际象棋; column2 ++)
{
string 结果;
if (line1 == 0 )
{
.. 。
}
}
}
}
分号是C#中的语句终结符,所以当你把它放在for循环的结束:
for ( var line1 = 0 ; line1 < chess; line1 ++);
{
for ( var coloumn2 = 0 ; coloumn2 < chess; coloumn2 ++);
它结束了你在其中声明的变量的范围。
非常感谢@orginal griff我没注意到@wearwolf谢谢
namespace ConsoleApplication3
{
class Program
{
public static void Main(string[] args)
{
int chess = 8;
string dark = "x";
string light = "y";
for (var line1 = 0; line1 < chess; line1++) ;
{
for (var coloumn2 = 0; coloumn2 < chess; coloumn2++) ;
{
string result;
if (LINE== 0)
{
}
}
}
} } }
What I have tried:
I JUST WANT TO DECLARE THIS LINE1 VAR IN IF CONDITION HOW TO DO IT I AM NEW IN C# SORRY FOR THE SILLY QUESTION
解决方案
Don't use var - use the actual variable type. It's not what's causing the problem in this case, it's that your caps KEY IS STUCK DOWN and you have spurious semicolons!
Try this:
public static void Main(string[] args) { int chess = 8; string dark = "x"; string light = "y"; for (var line1 = 0; line1 < chess; line1++) { for (var column2 = 0; column2 < chess; column2++) { string result; if (line1 == 0) { ... } } } }
Semicolon is a statement terminator in C#, so when you put one at the end of your for loops:
for (var line1 = 0; line1 < chess; line1++) ; { for (var coloumn2 = 0; coloumn2 < chess; coloumn2++) ;It ends the scope of the variable you declare within it.
thanks a lot @orginal griff I didn't noticed that @wearwolf thanks
这篇关于在IF条件声明VAR错误中的C#cosole app错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文