Home >Backend Development >C++ >How Can I Use VB.NET's InputBox Functionality in C#?

How Can I Use VB.NET's InputBox Functionality in C#?

Linda Hamilton
Linda HamiltonOriginal
2025-01-03 13:32:381007browse

How Can I Use VB.NET's InputBox Functionality in C#?

VB.NET InputBox in C#: Exploring the Microsoft.VisualBasic Namespace

In C#, the InputBox functionality of Visual Basic .NET (VB.NET) is accessible through a different approach.

To utilize the InputBox functionality in C#, you must begin by adding a reference to the Microsoft.VisualBasic namespace. This namespace contains the InputBox method, which resides under Microsoft.VisualBasic.Interaction.

Here's a detailed example of how to use the InputBox in C#:

using Microsoft.VisualBasic;

namespace InputBoxExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Prompt for a string input
            string input = Interaction.InputBox("Enter your name:");
            Console.WriteLine($"Hello, {input}!");
        }
    }
}

In this example, we prompt the user for a string input by using the Interaction.InputBox method. The method has several arguments, including the prompt, title, default value, and X and Y coordinates of the input box window. However, only the first argument for the prompt is mandatory.

The above is the detailed content of How Can I Use VB.NET's InputBox Functionality in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn