|
-
Apr 3rd, 2007, 01:55 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2.0] Function shortcut.
Just wondering if C# supported function shortcuts like defining a new variable for messagebox so like I could define msgbox to be the same as messagebox.show. Does C# support this?
I know i can do
C# Code:
private void msgbox(string str)
{
MessageBox.Show(str);
}
But that doesnt allow all the args to be accessed differently. Like if I want 1 time to just have the str i have to provide the other args if another message box needs it. Is there another way?
Last edited by high6; Apr 3rd, 2007 at 02:00 PM.
-
Apr 3rd, 2007, 03:21 PM
#2
Re: [2.0] Function shortcut.
using MB = System.Windows.Forms.MessageBox;
-
Apr 3rd, 2007, 05:52 PM
#3
Re: [RESOLVED] [2.0] Function shortcut.
You certainly can do as penagate suggested but you'd have to do it for each individual file. The VS IDE provides code snippets for what you're asking and there is already one for MessageBox.Show. Code snippets are included in Intellisense too. All you have to do is type "mb" and Intellisense will pop up and highlight the 'mbox' code snippet item. Press the Tab key twice and it will insret the code for MessageBox.Show and all you have to do is enter the text.
There are numerous code snippets included by default, including all the common code patterns like 'if' blocks, etc. Many are much more complex than 'mbox', for instance you can type "prop" and get the code snippet for a property, which will insert a private variable and a corresponding public property. Many code snippets also help you make changes to the default code by providing green highlights that are linked. You can use the Tab key to hop from green field to green field and if you change one of them any that are linked will also change. For instance, if you invoke the 'prop' code snippet and change the type of the variable the property type will change accordingly.
Note that you can also create your own code snippets. Explore and enjoy!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|