Can a static method be called inside another method?
The main question is how can I call a static method inside another method. Please, help!
public static class Class1
{
public static string RenderCompareStatus()
{
bool isFound = Class1.Found(id);
}
private static bool Found(string id)
{
}
// Error message: does not contain definition for found
+2
sa
source
to share
4 answers
I've expanded the sample into a fully working example:
using System;
public static class Class1
{
public static void Main()
{
Console.WriteLine(RenderCompareStatus());
}
public static string RenderCompareStatus()
{
String id = "test";
bool isFound = Found(id);
return "Test: " + isFound;
}
private static bool Found(string id)
{
return false;
}
}
And the results:
Test: False
EDIT: If the above example is similar to your code, but your code does not work, edit your question to provide more details, such as the exact error, getting, and a more complete sample of the code causing the error.
EDIT: changed public static bool Found(string id)
to private static bool Found(string id)
recompiled and it still works.
+5
source to share