2

In a recent interview I had this question.

Whats the error here? I know enough c# but I cant see an error. Can you?

Class x {
     protected string t1;
     public int t2;
}
Class y : x {
}
3
  • 2
    capital letter C in the keyword class :)
    – Tomek
    Feb 5, 2012 at 17:34
  • 3
    Copy/pasting it into Visual Studio would have answered it also, wouldn't it?
    – vgru
    Feb 5, 2012 at 17:36
  • the capital C, was a mispelling. so thats not the error. Feb 5, 2012 at 18:54

1 Answer 1

14

Well in terms of errors, we could start with Class instead of class. In terms of bad practice, virtually every line of it is a bad idea in my view:

  • Non-descriptive class names (x, y)
  • Class names which don't follow .NET naming conventions
  • Non-private fields
  • Non-descriptive field names

Basically, the types string and int are okay here - but every other non-whitespace, non-symbolic token would need changing before I let this into a codebase...

4
  • I was looking to errors, but this does compiles. However from my point of view the real error here is that the fields are non private. The other are just fxcop issues not real errors. Feb 5, 2012 at 18:20
  • @Locaaaa: at my job, FxCop errors are real errors, most of the time.
    – Joe
    Feb 5, 2012 at 18:28
  • @Locaaaaa: It won't compile with Class instead of class. A non-private field isn't a "real" error in that it's not an error from the compiler's point of view. I think it's more likely I'd end up occasionally using non-private fields in very specialized cases than that I'd ever have a class called x.
    – Jon Skeet
    Feb 5, 2012 at 18:49
  • indeed they are, but in an interview I dont think they are looking at those kinds of erros, maybe they are looking at design errors. If you were the interviewer what would satisfy you as an answer? to me it would be: Non-private fields Feb 5, 2012 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.