I am trying to solve a simple problem. But I am stuck by a simple problem I am confused by "context" in c#.
So for this simple problem I am solving Euler problem 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Timers;
namespace Euler
{
//Problem 1
//If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
//Find the sum of all the multiples of 3 or 5 below 1000.
class Problem1
{
public int Sum53(int args)
{
int num = 0;
int limit = 1000;
int sum = 0;
while (num < limit)
{
if ((num % 3 == 0) || (num % 5 == 0))
{
sum = sum + num;
num++;
}
else
{
num++;
}
}
string myAnswer = sum.ToString();
Console.WriteLine("This is the total :" + myAnswer);
return sum;
}
}
}
However I cannot actually get the sum value to print or return. The current code starts the console but does not print.
If I move the console.writleine out of this class or to its own class I receive myAnswer is not available in this context.
So what exactly is context and how do I use my value in context?