i created a method in a new library
this is my code
namespace ClassLibrary1
{
public class Class1
{
public static bool ISprime(int prime)
{
if (prime < 2)
return false;
else if (prime == 2)
return true;
else
{
for (int i = 2; i < prime; i++)
{
if (prime % i == 0)
return false;
else
return true;
}
}
}
}
}
- how can i call that method in my console ” program.cs “
- i got an error that said ” Error 2 ‘ClassLibrary1.Class1.ISprime(int)’: not all code paths return a value”
what does that mean ?
sorry i’m a new programmer.
1.) call the method by doing the following:
or
2.) You need to return some value at the very end of the method. I also changed some of the logic:
3.) Answering comment about what’s different from the logic. Try running this and you’ll see the differences.