Mots clés : c#.netinheritanceconstructorc#
98
public class MyExceptionClass : Exception { public MyExceptionClass(string message, string extrainfo) : base(message) { //other stuff here } }
80
class MyExceptionClass : Exception { public MyExceptionClass(string message, string extraInfo) : base(ModifyMessage(message, extraInfo)) { } private static string ModifyMessage(string message, string extraInfo) { Trace.WriteLine("message was " + message); return message.ToLowerInvariant() + Environment.NewLine + extraInfo; } }
76
public class MyClass : BaseClass { private MyClass(string someString) : base(someString) { //your code goes in here } public static MyClass FactoryMethod(string someString) { //whatever you want to do with your string before passing it in return new MyClass(someString); } }
60
public ClassName() : this(par1,par2) { // do not call the constructor it is called in the this. // the base key- word is used to call a inherited constructor } // Hint used overload as often as needed do not write the same code 2 or more times
52
public class MyExceptionClass : Exception { public MyExceptionClass(string message, Exception innerException): base(message, innerException) { //other stuff here } }