Home | | C Sharp and .NET Framework(CNF) | Getting and Displaying Input/ Output

Chapter: C# and .NET Framework

Getting and Displaying Input/ Output

The following programs show how the inputs to the program are provided interactively through keyboard during the program execution

GETTING AND DISPLAYING INPUT/ OUTPUT

 

Ø    The following programs show how the inputs to the program are provided interactively through keyboard during the program execution

 

Command Line Arguments

 

Ø    The Main method is the entry point of a C# console application or windows application. (Libraries and services do not require a Main method as an entry point.). When the application is started, the Main method is the first method that is invoked.

 

Ø    There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point. For more information, see /main (C# Compiler Options).

 

 

 

 

class TestClass

{

static void Main(string[] args)

{

 

// Display the number of command line arguments: System.Console.WriteLine(args.Length);

}

}

 

Overview

 

Ø    The Main method is the entry point of an .exe program; it is where the program control starts and ends.

 

Ø    Main is declared inside a class or struct. Main must be static and it should not be publicThe enclosing class or struct is not required to be static.

Ø    Main can either have a void or int return type.

 

Ø    The Main method can be declared with or without a string[] parameter that contains command-line arguments. When using Visual Studio to create Windows Forms applications, you can add the parameter manually or else use the Environment class to obtain the command-line arguments. Parameters are read as zero-indexed command-line arguments.

 

Ø    Unlike C and C++, the name of the program is not treated as the first command-line argument.

 

Using ReadLine method

Example:

using System;

class csharp

{

Public static void main()

{

Console.Write(―Enter here‖);

String disp=console.ReadLine();

Console.WriteLine(―Hello‖+disp);

}}

 

Write() – Display the information within line break

WriteLine() – Display the information with line break

 

+ operator – used as concatenation operator

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
C# and .NET Framework : Getting and Displaying Input/ Output |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.