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) { } } }

18th Feb 2017, 1:53 AM
Christopher
2 Antworten
+ 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());
18th Feb 2017, 2:02 AM
Tamra
Tamra - avatar
0
within the main class include add();
18th Feb 2017, 2:03 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar