0
How can I get output from this code, and where could I put it in the code.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { public class AddObjects { public int add(int a = 2, int b = 9) { return (a + b); } } class Program { static void Main(string[] args) { } } }
2 Answers
+ 7
To get the output from add, you first need an AddObjects object. Create one in Main() like this:
AddObjects varName = new AddObjects();
Then, call add() through the object, and store the result in an int variable, or print it out:
int result = varName.add();
Console.WriteLine("Result: " + varName.add());
0
within the main class include
add();