Intro To C# For Visual Programming Lab
Intro To C# For Visual Programming Lab
Programs
Visual Programming
Intro….
• C# is a programming language of .Net Framework.
• C# includes all topics of C# such as first example, control statements,
objects and classes, inheritance, constructor, destructor, this, static,
sealed, polymorphism, abstraction, abstract class, interface,
namespace, encapsulation, properties, indexer, arrays, strings, regex,
exception handling, multithreading, File IO, Collections etc.
What is C#
• C# is pronounced as "C-Sharp". It is an object-oriented programming
language provided by Microsoft that runs on .Net Framework.
• By the help of C# programming language, we can develop different types
of secured applications..
• Distributed applications (A distributed application is a program that runs
on more than one computer and communicates through a network.
Example : For example, web browsers are distributed applications.
Browsers require back-end software (servers on the World Wide Web
as well as front-end software installed on your workstation (e.g.,
Internet Explorer))
• Web service applications (Web services are self-contained,
modular applications that can be described, published, located, and
invoked over a network)
• Common Language Runtime (CLR) is a managed execution
environment that is part of Microsoft's . NET framework. CLR
manages the execution of programs written in different
supported languages.
• CLR transforms source code into a form of byte code known as
Common Intermediate Language (CIL)
C# Example: Hello World
• class Program
• {
• static void Main(string[] args)
• {
• System.Console.WriteLine("Hello World!");
• }
• }
• Output:
Hello World!
Description
• class: is a keyword which is used to define class.
• Program: is the class name. A class is a blueprint or template from which objects are created.
It can have data members and methods. Here, it has only Main method.
• static: is a keyword which means object is not required to access static members. So it saves
memory.
• void: is the return type of the method. It does't return any value. In such case, return
statement is not required.
• Main: is the method name. It is the entry point for any C# program. Whenever we run the C#
program, Main() method is invoked first before any other method. It represents start up of the
program.
• string[] args: is used for command line arguments in C#. While running the C# program, we
can pass values. These values are known as arguments which we can use in the program.
• System.Console.WriteLine("Hello World!"): Here, System is the namespace. Console is the
class defined in System namespace. The WriteLine() is the static method of Console class
which is used to write the text on the console
C# Example: Using System
• If we write using System before the class, it means we don't need to specify System namespace for
accessing any class of this namespace. Here, we are using Console class without specifying
System.Console.
• using System;
• class Program
• {
• static void Main(string[] args)
• {
• Console.WriteLine("Hello World!");
• }
• }
• Output:
• Hello World!
C# Example: Using public modifier
• We can also specify public modifier before class and Main() method. Now, it can be accessed
from outside the class also.
• using System;
• public class Program
• {
• public static void Main(string[] args)
• {
• Console.WriteLine("Hello World!");
• }
• }
• Output:
• Hello World!
C# Example: Using namespace
• We can create classes inside the namespace. It is used to group related classes. It is used to categorize
classes so that it can be easy to maintain.
• using System;
• namespace ConsoleApplication1
• {
• public class Program
• {
• public static void Main(string[] args)
• {
• Console.WriteLine("Hello World!");
• }
• }
• }
.NET Framework