Generating Method Stub in Visual Studio

Itorian
Posted by in Visual Studio category on for Beginner level | Points: 250 | Views : 11623 red flag

In this quick post you will learn how to generate method stub in Visual Studio.

Introduction

 

This post is for those who still don’t know Method Stub or using a boring style method writing technique. Visual Studio IDE has a great feature named Generate Method Stub which let generate Method Stub automatically.

 

What is Method Stub?

 

Method Stub is a feature that helps developer to generate the method codes by just clicking a button.

 

Let’s look what MSDN says:-

 

Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call.

 

Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.

 

The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.

 

Live Experiment

 

Okay, to experiment it here with me, follow the steps:

 

Step 1

 

Open the Visual Studio and create a new Console Application program.

 

Step 2

 

Type the following code in the page.

 

using System;

 

namespace demoMethodStub

{

    class Program

    {

        static void Main(string[] args)

        {

            itorian();

            Console.ReadKey();

        }

    }

}

 

In the above code, I just have place a method named itorian().

 

Step 3

 

Now right click on itorian() method and navigate to Generate > Method Stub, you will a method stub automatically, as given in image below.

 


 

Step 4

 

When you click that, you will get some codes that are called ‘Method Stub’. Now as per your need you can edit that code. I am just going to print a message using that method.

 


 

Step 5

 

Don’t worry if you are carrying some data in method call. Just write the data value in calling method like itorian(msg) and follow the same process as directed above.

 


 

That’s all about the Generating Method Stub in Visual Studio.

 

I hope you like it. Comments Please.

 

HAVE A HAPPY CODING!!

Page copy protected against web site content infringement by Copyscape

About the Author

Itorian
Full Name: Abhimanyu Kumar Vatsa
Member Level: Starter
Member Status: Member
Member Since: 4/21/2011 3:54:53 AM
Country: India
Student of M.Tech IT | Microsoft MVP | Mindcracker MVP | IT Faculty | Blogger | Author
http://www.itorian.com
Abhimanyu Kumar Vatsa (Abhimanyu Kumar Singh) is a Microsoft MVP and Mindcracker (C# Corner) MVP (2010, 2011) and having experience in building web scale applications using Microsoft Technologies including ASP.NET, MVC, C#/VB, jQuery, JavaScript, Silverlight, SQL Server and many more web stuffs. He is also handy in non-Microsoft Technologies like PHP, ColdFusion etc but he's specility is always Microsoft. He love to work with Internet scale projects using Microsoft stuffs that has potential to change the every day use of technology. He love to blog and started it around June 2009 and because such blogging Microsoft awarded him MVP.

Login to vote for this post.

Comments or Responses

Posted by: Akiii on: 8/15/2011 | Points: 25
Hi,
Good article about method stub.....indeed visual studio is a fine IDE !

Thanks and Regards
Akiii

Login to post response

Comment using Facebook(Author doesn't get notification)