Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, May 29, 2014

C# Programming Tutorial ( Part 2 )

As mentioned, the class is C#’s basic unit of encapsulation. Example is the name of the class. The class definition begins with the opening curly brace ({) and ends with the closing curly brace (}). The elements between the two braces are members of the class.
The next line of code is shown here:
static void Main() {
This line begins the Main( ) method. As mentioned earlier, in C#, a subroutine is called a method. As the comment preceding it suggests, this is the line at which the program will begin executing. All C# applications begin execution by calling Main( ).
The line begins with the keyword static. A method that is modified by static can be called before an object of its class has been created. This is necessary because Main( ) is called at program startup. The keyword void indicates that Main( ) does not return a value.
The next line of code is shown here. Notice that it occurs inside Main( ).
Console.WriteLine(“A simple C# program.”);

This line outputs the string “A simple C# program.” followed by a new line on the screen. Output is actually accomplished by the built-in method WriteLine( ).

Second program
using System;
class Example2 {
      static void Main() {
                         int    x; // this declares a variable
                         int    y; // this declares another variable
                         x = 100; // this assigns 100 to x
                          Console.WriteLine(“x contains ” + x);
                          y = x / 2;
                          Console.Write(“y contains x / 2: “);
                          Console.WriteLine(y);
                       }
                 }


Another example
                   using System;
                  class Example3 {
                    static void Main() {
                           int     ivar; // this declares an int variable
                           double dvar; // this declares a floating-point variable
                           ivar = 100; // assign ivar the value 100
                          dvar = 100.0; // assign dvar the value 100.0
                          Console.WriteLine(“Original value of ivar: ” + ivar);
                          Console.WriteLine(“Original value of dvar: ” + dvar);
                           Console.WriteLine(); // print a blank line
                          // Now, divide both by 3.
                          ivar = ivar / 3;
                          dvar = dvar / 3.0;
                          Console.WriteLine(“ivar after division: ” + ivar);
                          Console.WriteLine(“dvar after division: ” + dvar);
                        }
                       }

C Programming Tutorial ( Part 2 )

Programming Basic :

PCs could be linked together in computer networks over
telephone lines or in local area networks (LANs) within an
organization
Information is shared easily across computer networks, where
computers are called servers (e.g. file servers, database servers,
web servers, etc.) offer capabilities that may be used by client
computers distributed throughout the network
C program is widely used for writing software for operating
systems, computer networking, and for client/server applications

Programmers write instructions in various programming
languages, some directly understandable by computers and
others require intermediate translation steps
Programming languages can be divided into three general
classes:
1 Machine languages
2 Assembly languages
3 High-level languages

Thursday, May 22, 2014

C# Programming Tutorial ( Part 1 )

A first simple program

/*
This is a simple C# program. Call this program Example.cs.
*/
using System;
class Example {
// A C# program begins with a call to Main().
static void Main() {
Console.WriteLine(“A simple C# program.”);
}
    }

The primary development environment for C# is Microsoft’s Visual Studio. To compile all of the programs in this book, including those that use the new C# 4.0 features, you will need to use a version of Visual Studio 2010 (or later) that supports C#. Using Visual Studio, there are two general approaches that you can take to creating,
compiling, and running a C# program. First, you can use the Visual Studio IDE. Second, you can use the  command-line compiler, csc.exe. To actually run the program, just type its name of the program  on the command line.



Explanation

using System;
This line indicates that the program is using the System namespace. In C#, a namespace defines a declarative region. Through the use of namespaces, it is possible to keep one set of names separate from another. In essence, names declared in one namespace will not conflict with names declared in a different namespace. The namespace used by the program is System, which is the namespace reserved for items associated with the .NET Framework class library, which is the library used by C#. The using keyword simply states that the program is using the names in the given namespace.

C Programming Tutorial ( Part 1 )

Programming Basic :
A computer is a device that can perform computations and make
logical decisions billions of times faster than human beings can,
e.g. many personal computers (PCs) can perform several billion
additions per second.
Computers process data under the control of sets of instructions
called computer programs
These programs guide the computer through orderly sets of
action specified by people called computer programmers
A computer consists of various devices (e.g. keyboard, screen,
mouse, hard disk, memory, etc.) referred to as hardware
The programs that run on a computer are referred to as
software, e.g. Microsoft word, anti-virus program, etc.