2. Terminologies in C Sharp .
a. Structure
Structure is a user-defined value type which encapsulates member data and member function.
A struct is a user-defined value type. It is declared in a very similar way to a class, except that it can't inherit from any class, nor can any class inherit from it (as mentioned previously, however, all value types do inherit from System.object. It capsules all the variable under one roof .
b. Scope of variable
Using System;
Class Exercise
{
Static double Length;
Static void welcome()
{
console. WriteLine ("welcome to the wonderful world of c#");
}
Static void Main ()
{
Welcome();
console. WriteLine ();
}
}
After declaring such a variable, you can access from any method that belongs to the same class. Here is an example, to understand the concept of static variable.
Use of static variable
using System;
class Cylinder
{
static double Length;
static double Width;
static double Area;
static double Get The Length ()
{
double Len;
console. Write ("Length: ");
Len= double. Parse (console. Read Line ());
return 1en;
}
static double GetThewidth()
{
double w;
console. Write ("width: ");
w = double. Parse (console. Read Line ());
return w;
}
static void AreaRect ()
{
console. WriteLine ("Enter the Length and width of Rectangle ");
width = Get The width();
Length = Get The Length();
Area = Length * width;
}
static void show Area()
{
console. Write Line(" characteristics of Rectangle");
console. write Line("Length: "+ Length);
console. Write Line("width :"+ width);
Console. Write Line("Area :"+ Area); }
}
static void Main()
{
AreaRect ();
Show Area() ;
console. Write Line (); }
}
}
OUTPUT:
Enter the Length and Width of Rectangle
Length: 38.24
Width: 32.58
Characteristics of Rectangle
Length: 38.24
Width: 32.58
Area : 1245.85
When many people work in creating the same program, it could be difficult to keep track of the names of various classes. If more than one programmer creates a class with the same name in the same program, there would be conflict and the program would not work. The solution to avoid this situation is to delimit sections of code with names.
A namespace is a collection of classes. Namespaces in C# are used to organize too many classes so that it can be easy to handle the application.
d. Identifiers
Identifiers refer to the names of variables, functions arrays, classes, etc. created by programmer. They are fundamental requirement of any language. Each language has its own rules for naming these identifiers. To name the variables of your program, you must follow strict rules. In fact, everything else in your program must have a name.
Command line arguments are parameters supplied to the Main method at the time of invoking it for execution. To understand the concepts see the example given below:
Program of Command line argument to accept name from the command line and writes to the console. (Sample.cs)
using System;
class sample
{
public static void Main( string[ ] args)
{
console.write("welcome to");
console.write(" " +args[0]);
console.write(" " +args[l]);
}
}
Execution for this program
C: > Sample My Home
Output of Example
Welcome to My Home
In Previous examples, we have used the Main method with no parameters. Notice that in the above example how the Main is declared.
Main is declared with a parameters args. The parameter args is an array of strings. Any arguments provided in the command line at the time of execution, are passed to the array args as its elements. We can access the array elements by using a subscript like args[0],args[1] and so on.
Like as in the command line" C:> Sample My Home", args[O] and args[1] contains:
Args [0] <-- My
args [1] <-- Home
There fore the values will be display of these parameters in Console.Write() statement.