Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Function shortcut.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Resolved [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:
    1. private void msgbox(string str)
    2.         {
    3.             MessageBox.Show(str);
    4.         }

    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.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Function shortcut.

    using MB = System.Windows.Forms.MessageBox;

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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!
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width