If-Anweisung
Eine if-Anweisung, auch bekannt als Bedingungsanweisung, ist eine Methode, um einen Codeblock basierend auf einer Bedingung auszuführen. Die Syntax einer if-Anweisung ist folgende:
if(condition) {
// code to execute
}
Sie nimmt einen Ausdruck und führt den Codeblock aus, wenn der Ausdruck true
ist.
Zum Beispiel:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 9) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Falls die Bedingung false
ist, wird der Codeblock ignoriert:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 10) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 1.59
If-Anweisung
Swipe um das Menü anzuzeigen
Eine if-Anweisung, auch bekannt als Bedingungsanweisung, ist eine Methode, um einen Codeblock basierend auf einer Bedingung auszuführen. Die Syntax einer if-Anweisung ist folgende:
if(condition) {
// code to execute
}
Sie nimmt einen Ausdruck und führt den Codeblock aus, wenn der Ausdruck true
ist.
Zum Beispiel:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 9) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Falls die Bedingung false
ist, wird der Codeblock ignoriert:
main.cs
12345678910111213141516using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { Console.WriteLine("Before Conditional"); if(10 > 10) { Console.WriteLine("10 is greater than 9"); } Console.WriteLine("After Conditional"); } } }
Danke für Ihr Feedback!