it's possible?
based in another's examples, as LabelExtesios, StringExtensions, etc. I wrote this:
namespace MessageBoxExtensions
{
public static class MessageBoxExtensionsClass
{
public static void Foo()
{
}
}
}
then:
using MessageBoxExtensions;
// ...
MessageBox.Foo();
gin an error: MessageBox.Foo();
'System.Windows.Forms.MessageBox' does not contain a definition for 'Foo'
An extension method must be defined in a top-level static class. An extension method with the same name and signature as an instance method will not be called. Extension methods cannot be used to override existing methods. The concept of extension methods cannot be applied to fields, properties or events.
Extension methods require an instance variable (value) for an object. You can however, write a static wrapper around the ConfigurationManager interface. If you implement the wrapper, you don't need an extension method since you can just add the method directly.
A message box is a prefabricated modal dialog box that displays a text message to a user. You show a message box by calling the static Show method of the MessageBox class. The text message that is displayed is the string argument that you pass to Show.
To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.
You cant do this because System.Windows.Forms.MessageBox
is NOT an instance of MessageBox
. MessageBox.Show()
is a static method.
You cant create an instance of MessageBox
because this class has no public constructor.
But you can create your own class in the System.Windows.Forms
namespace and use the
MessageBox
in this method like this
namespace System.Windows.Forms
{
public static class MyCustomMessageBox
{
public static void Foo()
{
MessageBox.Show("MyText");
}
}
}
MyCustomMessageBox.Foo();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With