C
C#13mo ago
Saltys_Salty

✅ 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
4 Replies
Saltys_Salty
Saltys_Salty13mo ago
Please ping in response! Thank you in advance
daysleeper
daysleeper13mo ago
i dont really get what your palindromeCheck() is supposed to do but to resolve your issues: first off you cant declare "void int" there can only be one return type - either void or int. your Main() method is the part that executes in C#, so you need to invoke your method inside it. then you mustnt create an instance of Program. you need to make methods static (you only did it to Reverse method) and you will be able to to do what you want. there are probably some more issues which i cant think of right now but you can say which errors you get afterwards
Saltys_Salty
Saltys_Salty13mo ago
Yes! Everything is now working, thank you so much
Saltys_Salty
Saltys_Salty13mo ago
Want results from more Discord servers?
Add your server
More Posts
❔ Missing assembly reference using PackageReferenceI updated to package references a short while ago, now when I change development environments (git cUnsure when to load data .NET MAUII am trying to load the Ingredient value from my sqlite db and it doesnt load when im calling it wit✅ Modify embedded resources at runtimeIs there a way to modify an assembly's *own* embedded resources? I'm not looking into physically cha❔ Getting Identity from [Authorize]Hey there, since i'm using [Authorize] i thought i should be able to get UserID from var userId = H❔ Tasked with making a scheduling algorithm at summer internshipI'm an industrial engineering student that knows a bit of coding, but it seems like I've been given ❔ ✅ Search for specific value that is contained inside some variable while debugging VSWhen debugging a large project, I know that one of my many variables will contain a string valled "VIIS Worker (30%) and SQL Server (60%) High CPU usage.Currently hosting a website on iis (.net core 3.1). I have no clue as to why usage for both the iis ❔ Trying to make an app using rustI come from a background of asp net core, where I worked with the framework for over a year and has ❔ Visual Studio Code doesn't highlight a syntax error in C# (with Unity)I have the Unity Debugger and C# plugins, and still nothing comes up. I know it is an error becasue ❔ AutoSize always shrinks my control to 1 px even with contentI have a User Control that has 3 panels in it. One docked to the top, one to fill and one to the bot