1

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.

4
  • ok wait i will add here debug Commented Dec 18, 2013 at 18:28
  • 2
    You're not using the login variable at all after initializing it. Think about that. Commented Dec 18, 2013 at 18:28
  • Skeet is right, I skimmed through the code too quickly. Just because you inherit from the same base does not mean that it is the same object Commented Dec 18, 2013 at 18:30
  • I added to my post debugg for login and password output. Commented Dec 18, 2013 at 18:33

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

problem is not here access.ValidateLogin(loginText.Text, passwordText.Text); Problem is that in second step i defined Login and Password for class Collections but in third step this definion is again empty. (null)
@RadekTarant, they aren't the same instance of the object. How would the values persist, or migrate, between instances?
Thx for help i little edited this ´access.ValidateLogin(login.Login, login.Password);´ and now its works. THX!
@Radek, I'm glad I could be of assistance!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.