Generating 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

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples