+ 1
Strange problem with if-else
I remember this tip in if-else lesson: "When only one line of code is in the if block, the curly braces can be omitted." So let's test this : // Suppose that everything is okay and the condition is true. (Edited) using System; namespace Test { class Program { static void Main(string[] args) { string Value2 = "Hello"; if (true) var Value1 = Value2; // Error : Embedded statement cannot be a declaration or labeled statement } } } So we're not able to omitt curly braces in this situation. Tested in visual studio 2015 Any idea about why such a thing is not possible?
4 odpowiedzi
+ 2
What's around that IF statement? What does "something" consist of?
+ 2
@Jamie
Thanks for your great answer.
+ 1
show us the whole code, what is something
0
OK let me make it clearly.
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string Value2 = "Hello";
if (true)
var Value1 = Value2; // Error: Embedded statement cannot be a declaration or labeled statement.
}
}
}