0% found this document useful (0 votes)
15 views

intro to C#

Uploaded by

Shiva Dhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

intro to C#

Uploaded by

Shiva Dhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

C# Programming, its

features, oops using c#

Ms. Nausheeda B.S


The following reasons make C# a widely used professional language:
• Modern, general-purpose programming language
• Object oriented.
• Component oriented.
• Easy to learn.
• Structured language.
• It produces efficient programs.
• It can be compiled on a variety of computer platforms.
• Part of .NET Framework.
Features
• C# is a simple , modern, object oriented language derived from C++ and Java.

• It aims to combine the high productivity of Visual Basic and the raw power of
C++.

• IDE Microsoft Visual Studio.(latest version - Visual Studio 2022 version 17.8)

• Visual studio supports VB , VC++,C++, VBScript, Jscript . All of these


languages provide access to the Microsoft .NET platform.

• .NET includes a Common Execution engine and a rich class library.


• CLR accommodates more than one languages such as C#, VB.NET, Jscript,
ASP.NET,C ++.

• Source code --->Intermediate Language code(IL) ---> (JIT Compiler) Native code.

• The classes and data types are common to all of the .NET languages.

• We may develop Console application , Windows application , Web application


using C#.

• In C# Microsoft has taken care of C++ problems such as Memory management,


pointers etc.

• It support garbage collection, automatic memory management.

• Latest version of C# is C# 1.0, which was released in Nov 2023 in .NET 8.0
MAIN FEATURES OF C#

1. SIMPLE
2. MODERN
3. OBJECT ORIENTED
4.TYPE SAFE
5.INTEROPERABILITY
6.SCALABLE AND UPDATEABLE

CONCLUSION
• C# is a modern, type safe programming language, object oriented language
that enables programmers to quickly and easily build solutions for the
Microsoft .NET platform
Compile & Execute a C# Program:
• If you are using Visual Studio . Net for compiling and executing C# programs, take
the following steps:

• Start Visual Studio.

• On the menu bar, choose File, New, Project.

• Choose Visual C# from templates, and then choose Windows.

• Choose Console Application.

• Specify a name for your project, and then choose the OK button.

• The new project appears in Solution Explorer.

• Write code in the Code Editor.

• Click the Run button or the F5 key to run the project. A Command Prompt window
appears that contains the line Hello World.
• You can compile a C# program by using the command-line instead of the
Visual Studio IDE:

• Open a text editor and add the above-mentioned code.

• Save the file as helloworld.cs

• Open the command prompt tool and go to the directory where you
saved the file.

• Type csc helloworld.cs and press enter to compile your code.

• If there are no errors in your code, the command prompt will take you to
the next line and would generate helloworld.exe executable file.

• Next, type helloworld to execute your program.

• You will be able to see "Hello World" printed on the screen.


Executing the Program

File Name To Compile To Execute

Hello.class
Hello.java javac Hello.java java Hello

Hello.exe
Hello.cs csc Hello.cs Hello
C# Hello World Example

• A C# program basically consists of the following parts:

• Namespace declaration
• A class
• Class methods
• Class attributes
• A Main method
• Statements & Expressions
• Comments

• Let us look at a simple code that would print the words "Hello World":
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}

• When the above code is compiled and executed, it produces the following
result:
• Hello World
using System;
namespace first_space
{
class firstclass
{
public void func()
{
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space
{
class secondclass
{
public void func()
{
Console.WriteLine("Inside second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
first_space.firstclass fc = new first_space.firstclass();
second_space.secondclass sc = new second_space.secondclass();
fc.func();
sc.func();
Console.ReadKey();
}
}
using System;
using first_space;
using second_space;

namespace first_space
{
class abc {
public void func()
{
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space
{
class efg
{
public void func()
{
Console.WriteLine("Inside second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
abc fc = new abc();
efg sc = new efg();
fc.func();
sc.func();
Console.ReadKey();
}
}
using System;
using first_space;
using first_space.second_space;

namespace first_space {
class abc {
public void func() {
Console.WriteLine("Inside first_space");
}
}
namespace second_space {
class efg {
public void func() {
Console.WriteLine("Inside second_space");
}
}
}
}
class TestClass {
static void Main(string[] args) {
abc fc = new abc();
efg sc = new efg();
fc.func();
sc.func();
Console.ReadKey();
}
}
When the above code is compiled and executed, it produces the
following result −

Inside first_space
Inside second_space
using System;
using first_space;
using nested.second_space;

namespace first_space {
class abc {
public void func() {
Console.WriteLine("Inside first_space");
}
}
}
namespace nested{
namespace second_space {
class efg {
public void func() {
Console.WriteLine("Inside second_space");
}
}
}
Command Line Arguments
• In order to make our program to behave in a particular way depending
on the input provided at the time of execution we use Command Line
Arguments.
• They are parameters supplied to the Main method at the time of
invoking it for execution.
• For Example:
static void Main(string [] args)
{
Console.WriteLine(“Welcome “ + args[0]);
}
Creating an Interactive Applications
• Another important Method in the Console Class is the
ReadLine() Method.
• It is used to receive an input from the user while the
program is executing.
• By Default whatever the method receives from the user is
considered as string.
• So, if a particular data type is expected from the user it is
recommended to either use the Convert or Parse Classes.
Example

using System;
namespace sqrtappliccation
{
class squareroot
{
static void Main()
{
double a,b;
Console.WriteLine("Enter a Number");

a = double.Parse(Console.ReadLine());
Or
a = Convert.ToDouble(Console.ReadLine());
b = Math.Sqrt(a);
Console.WriteLine(“The Square Root of “ + a + ” is “ + b);
}
using System;
namespace firstappliccation
{
class evenodd
{
static void main(String[] args)
{
int n;
Console.WriteLine(“enter the number”);
n=Convert.ToInt32(Console.ReadLine());
if(n%2==0){
Console.WriteLine(“even”);
}else{
Console.WriteLine(“odd”);
}
Console.ReadKey();
}
}
}
Thank you

You might also like