Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Défi : Valeurs de Retour | Méthodes
Quizzes & Challenges
Quizzes
Challenges
/
Bases de C#

bookDéfi : Valeurs de Retour

Here operate is a method which is supposed to return true if a + b equals c. Fill in the blank to make the method behave accordingly.

main.cs

main.cs

copy
12345678910111213141516171819
using System; namespace ConsoleApp { internal class Program { static __ operate(int a, int b, int c) { __; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
  1. We can write expressions directly in the return statement.
  2. For-example, writing return a + b; is valid as it will first evaluate a + b and in-turn return the resultant value. Similarly, we can also directly write boolean expressions in the return values, as boolean expressions are expressions after all. Hence, writing return a > b; is also valid. Using this information, think of a way how you can write a boolean expression that returns true if the sum of a and b is greater than c.
main.cs

main.cs

copy
12345678910111213141516171819
using System; namespace ConsoleApp { internal class Program { static bool operate(int a, int b, int c) { return (a + b) == c; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 6. Chapitre 7

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookDéfi : Valeurs de Retour

Glissez pour afficher le menu

Here operate is a method which is supposed to return true if a + b equals c. Fill in the blank to make the method behave accordingly.

main.cs

main.cs

copy
12345678910111213141516171819
using System; namespace ConsoleApp { internal class Program { static __ operate(int a, int b, int c) { __; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }
  1. We can write expressions directly in the return statement.
  2. For-example, writing return a + b; is valid as it will first evaluate a + b and in-turn return the resultant value. Similarly, we can also directly write boolean expressions in the return values, as boolean expressions are expressions after all. Hence, writing return a > b; is also valid. Using this information, think of a way how you can write a boolean expression that returns true if the sum of a and b is greater than c.
main.cs

main.cs

copy
12345678910111213141516171819
using System; namespace ConsoleApp { internal class Program { static bool operate(int a, int b, int c) { return (a + b) == c; } static void Main(string[] args) { Console.WriteLine(operate(1, 2, 3)); Console.WriteLine(operate(2, 4, 1)); Console.WriteLine(operate(5, 10, 15)); } } }

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 6. Chapitre 7
some-alt