Hi is it possible to specify a method that is the default method for a C# class? I am writing a short class to output embed code for a video, here is the basic idea:
public class EmbeddedVideo
{
public string VideoPath { get; set; }
public string ImagePath { get; set; }
public string EmbedCode()
{
return "...";
}
}
Now if I were to say:
Response.Write(new EmbeddedVideo());
It would output the result of the GetType() method. How can I specify that I would like the EmbedCode() method to be the default in this context?
Override
ToString(), which gets called in many scenarios where string conversion takes place:The “default” you’re referring to is the default implementation of
Object.ToString(), which simply happens to return the type name: