I recently had an interview with C # questions. One of them I can not find the answer.
I was assigned a class that looks like this:
public class Stick { private int m_iLength; public int Length { get { return m_iLength; } set { if (value > 0) { m_iLength = value; } } } }
A core class was also provided.
static void Main(string[] args) { Stick stick = new Stick(); }
The task was to add code to the main one, which would cause m_iLength in the Stick class to be negative (and it was emphasized that this could be done).
I think I missed something. The data element is private, and as far as I know, the get and set function has an int value, so I donβt see how this can be done.
source share