Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 39
    Its also worth noting you can chain constructors in your current class by substituting this for base. Commented Aug 15, 2008 at 13:30
  • It is here learn.microsoft.com/en-us/dotnet/csharp/language-reference/… Commented Jul 29, 2020 at 2:48
  • Try: public class MyExceptionClass : Exception { public MyExceptionClass(string message, string extrainfo) : base(message) { //other stuff here } } Commented Jul 18, 2021 at 7:30
  • @Quibblesome I haven't been able to find an example substituting .this for .base. I'm probably not phrasing it right, but do you have any examples? My question is if you do substitute, do you no longer need :base in the arguments and can just use .base in the constructor? Commented Feb 7, 2022 at 19:59
  • @DavidMays I mean instead of doing ctor():base(argTheBaseClassNeeds) you can do ctor():this(DateTime.Now) ctor(DateTime dt){ /* some impl */ }. In such as a case I am chaining a constructor in the current class to make the default date time value DateTime.Now. Commented Mar 30, 2023 at 22:34