C# is an object oriented Language and the main building block is the class.
You can’t call a method defined inside a class without creating an instance of that class.
(Unless you declare the method static, but this is not really the matter here)
So suppose you have this class
public class AClassOfMine
{
public DateTime CalculateNewDate(DateTime newDate)
{
//datetimecalculations
return calculatedDate;
}
}
if you want to use that method you need an instance of that class
public void methodName(param,param)
{
foreach loop(param)
{
If (item != null)
{
DateTime newDate = item.Date.value;
AClassOfMine anInstance = new AClassOfMine();
item.item.date = anInstance.CalculateNewDate(newDate);
}
}
}
of course the method CalculateNewDate
is supposed to return a new date so your method signature should be changed accordingly. (Return a date)
3
solved C# Error does not exist in the current context