programme structure in C#

Programme Structure In C# language-: Like any other language C# has a Programming structure.  C# are programs, namespaces, types, members, and assemblies. C# programs consist of one or more source files. these list..

  • Programme declare types-: It contain members and can be organized into namespaces.
  • Classes and interfaces are examples of types.
  • Fields
  •  methods
  • properties
  • events are examples of members.
  • Class methods
  • Class attributes

When C# programs are compiled, they are physically packaged into assemblies. Assemblies typically have the file extension .exe or .dll, depending on whether they implement applications or libraries.

Like a example ..

 

c#

declares a class named Stack in a namespace called Acme.Collections. The fully qualified name of this class is Acme.Collections.Stack. The class contains several members,a field named top, two methods named Push and Pop, and a nested class named Entry.

The Entry class further contains three members

  • a field named next
  • a field named data
  • a constructor.

Assuming that the source code of the example is stored in the file acme.cs, the command line

csc /t:library acme.cs

compiles the example as a library (code without a Main entry point) and produces an assembly named acme.dll.

Assemblies contain executable code in the form of Intermediate Language (IL) instructions, and symbolic information in the form of metadata. Before it is executed, the IL code in an assembly is automatically converted to processor-specific code by the Just-In-Time (JIT) compiler of .NET Common Language Runtime.

Because an assembly is a self-describing unit of functionality containing both code and metadata, there is no need for #include directives and header files in C#. The public types and members contained in a particular assembly are made available in a C# program simply by referencing that assembly when compiling the program. For example, this program uses the Acme.Collections.Stack class from the acme.dll assembly:

using System;
using Acme.Collections;

class Test
{
static void Main() {
Stack s = new Stack();
s.Push(1);
s.Push(10);
s.Push(100);
Console.WriteLine(s.Pop());
Console.WriteLine(s.Pop());
Console.WriteLine(s.Pop());
}
}

If the program is stored in the file test.cs, when test.cs is compiled, the acme.dll assembly can be referenced using the compiler’s /r option:

csc /r:acme.dll test.cs

The output of this programme .

100

10

1

C# permits the source text of a program to be stored in several source files. When a multi-file C# program is compiled all of the source files are processed together and the source files can freely reference one another—conceptually it is as if all the source files were concatenated into one large file before being processed.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *