Saltys_Salty
Saltys_Salty
CC#
Created by Saltys_Salty on 6/20/2023 in #help
✅ Member '<member name>' cannot be accessed with an instance reference
namespace palidromeDepth
{
internal class Program
{
static void Main(string[] args)
{

}
void int palidromCheck(int depth, int number)
{
Program program = new Program(); // Defines program
string reversed = program.Reverse(Convert.ToString(number); // Supposed to get a reverse of the number
if (Convert.ToString(number) == reversed)
{
return depth; // returns all and sends depth to the user
}
else
{
return palidromCheck(depth+1, number+Convert.ToInt16(reversed)); // Runs the module again
}

}
static string Reverse(string word)
{
// Converts to Array, reverses array, then converts back to string
char[] charArray = word.ToCharArray();
Array.Reverse(charArray);
return new string(charArray); // SHOULD return reversed string
}
}

}
namespace palidromeDepth
{
internal class Program
{
static void Main(string[] args)
{

}
void int palidromCheck(int depth, int number)
{
Program program = new Program(); // Defines program
string reversed = program.Reverse(Convert.ToString(number); // Supposed to get a reverse of the number
if (Convert.ToString(number) == reversed)
{
return depth; // returns all and sends depth to the user
}
else
{
return palidromCheck(depth+1, number+Convert.ToInt16(reversed)); // Runs the module again
}

}
static string Reverse(string word)
{
// Converts to Array, reverses array, then converts back to string
char[] charArray = word.ToCharArray();
Array.Reverse(charArray);
return new string(charArray); // SHOULD return reversed string
}
}

}
When I call it the way I am doing here, it tells me I need to do it with an instance reference, how would I do that? How would I call my string reverse code? Do I need to change on how I name it? Sorry I am pretty new to C# and only started learning it today
5 replies