Error message is:
'_djv.Authenticator' does not contain a definition for 'authenticate' and no extension method 'authenticate' accepting a first argument of type '_djv.Authenticator' could be found (are you missing a using directive or an assembly reference?) my code is below, I have a console app program and a class called authenticator, both pieces of code are down there.
namespace _Authenticator
{
public class Authenticator
{
private Dictionary < string, string > dictionary = new Dictionary < string, string > ();
public Authenticator()
{
dictionary.Add("username1", "password1");
dictionary.Add("username2", "password2");
dictionary.Add("username3", "password3");
dictionary.Add("username4", "password4");
dictionary.Add("username5", "password5");
}
public bool authenticate(string username, string password)
{
bool authenticated = false;
if (dictionary.ContainsKey(username) && dictionary[username] == password)
{
authenticated = true;
}
else
{
authenticated = false;
}
return authenticated;
}
}
}
using _Authenticator;
namespace _djv
{
class Authenticator
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a username");
var username = Console.ReadLine();
Console.WriteLine("Please enter your password");
var password = Console.ReadLine();
var auth = new Authenticator();
if (auth.authenticate(username, password))
Console.WriteLine("Valid username/password combination");
else
Console.WriteLine("Invalid username/password combination");
Console.WriteLine("Press Enter to end");
Console.ReadLine();
}
}
}
There is a clash of class names. Your auth
variable refers to the class inside _djv
namespace. Specify the full name of the class to be able to use it.
var auth = new _Authenticator.Authenticator();
Alternatively, you can create an alias for the class. I'd recommend this approach here as it makes writing code less tedious.
using Auth = _Authenticator.Authenticator;
(...)
var auth = new Auth();
Actually, I think the best idea would be to rename one of the classes. Everything will get a lot cleaner and clearer.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments