0

I have a piece of code that produces the following output

new tutor(new lecturer(new coursecoordinator()))

I need a way to allow c# to execute this as a string however after searching I have not been able to find any examples that relate to string such as these. Any ideas as to the best way of approaching this would be appreciated.

JOsh
  • 169
  • 2
  • 4
  • 15

1 Answers1

0

If I understand correctly, then you should be able to do it via the implicit operator overload. Here it is on MSDN

//To use, put in the "tutor" class.
public static implicit operator string(tutor t)
{
    //return the tutor object, in string form.
    //For the example, I just return the .ToString() function found on all objects.
    return t.ToString();
}

This will let you seamlessly use the statement "new tutor(new lecturer(new coursecoordinator()))" as a string. EDIT: I think I misunderstood, perhaps this answer will help a passer-by anyway.

Community
  • 1
  • 1
RoyalPotato
  • 515
  • 4
  • 15