Pergunta

Please, can you help me how can i get data from class for second Initialize. Problem is that for third Step is "Login" and "Password" -> Null But i defined this "Login" and "Password" in second step. Can you tell me why is login and password for third step null and how can i fix it? I wont create static class for this.

Foi útil?

Solução

So unless I'm missing something here:

access.ValidateLogin(login.Login, login.Password);

The login object has the values you set during the process of getting data.


If you're not going to leverage the same object, and you want them the same, then I guess you'd have to do this:

LoginValidation access = new LoginValidation();
access.Login = login.Login;
access.Password = login.Password;
access.ValidateLogin(loginText.Text, passwordText.Text);

But this is really odd. It will work, but this just doesn't make sense at all.

Outras dicas

To elaborate on the comments for learning purposes.

Inheritance != Object Reference

Give the following:

public class A
{
  public String Foo;
}

public class B : A
{
  SetFoo(String foo)
  {
    Foo = foo
  }
}

public class C : A
{
  UseFoo()
  {
    PrintLn(Foo);
  }
}

When you create the object B and set Foo, that does not set the Foo in C simple because they both inherit from A. They are different objects, so have different references to their own Foo

So, your code could do something like this and be correct :

public void Main()
{
  var validLoginInfo = new LoginInfo(loginText.Text)
  var isValid = new LoginValidator(loginText.Text, passwordText.Text, validLoginInfo).Validate();
  ...
}

Then you can use the given values and compare to the valid login information.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top