0

Follow up from This Question -

In the Question class I have the following properties (I'm simplifying here)

public class Question : IDisposable, IEquatable<Question>{
    protected virtual DataRow Row{ get { return DataTable.Rows[0]; } }
    public string Value { get { return this.Row.Field<string>("Value"); } }
}

now, for the SessionQuestion class I want to keep this in play, but I want to read the Value field from a different data table :

public class SessionQuestion : Question, IEquatable<SessionQuestion>{
    protected override DataRow Row { get { return OtherDataTable.Rows[0]; } }
}

Now, if I were to say something like :

new SessionQuestion( ).Value

would that return the value from DataTable.Rows[0], or OtherDataTable.Rows[0]? I want it to return the value from OtherDataTable, so if this doesn't work, what would I need to do so it would work properly?

Community
  • 1
  • 1
Will
  • 3,413
  • 7
  • 50
  • 107
  • Didn't you mean *SessionQuestion* inheriting from *Question*? In your code in the question *SessionQuestion* does not inherit *Question*... ;) –  Aug 15 '15 at 22:00
  • fffffff...ixed thanks. – Will Aug 15 '15 at 22:01
  • Why don't you try it out and see.... – DavidG Aug 15 '15 at 22:01
  • It would return `OtherDataTable.Rows[0]`, because *SessionQuestion*'s *Row* property **override**s the implementation of the *Row* property in *Question* ;) –  Aug 15 '15 at 22:03
  • Serious point though, in both this question and your previous one, you could have figured it out by running both examples. – DavidG Aug 15 '15 at 22:10
  • @DavidG This wasn't some sort of rep grab; while these would be simple enough to write a 15 minute application, then what? I could still post the question and answer it myself, or I could ask the question and many people could benefit. – Will Aug 15 '15 at 22:28
  • Surely if it takes you longer to write the questions than work out the answers for yourself, then those questions don't need to be asked on SO? – DavidG Aug 15 '15 at 23:27

0 Answers0