Basic Introduction To C#
Basic Introduction To C#
Basic Introduction
Introduction to
to C#
C#
Why C# ?
• Native support for
– Namespaces
– Versioning
– Attribute-driven development
• Power of C with ease of Microsoft Visual
Basic®
• Minimal learning curve for everybody
• Much cleaner than C++
• More structured than Visual Basic
• More powerful than Java
C# – The Big Ideas
A component oriented language
• The first “component oriented” language in
the C/C++ family
– In OOP a component is: A reusable program that can be
combined with other components in the same system to
form an application.
– They can be deployed on different servers and
communicate with each other
• Character Types
– char (single character)
– string (rich functionality, by-reference type)
• Boolean Type
– bool (distinct type, not interchangeable with int)
Arrays
• Built on .NET System.Array class
• Declared with type and shape, but no bounds
– int [ ] SingleDim;
– int [ , ] TwoDim;
– int [ ][ ] Jagged;
• Created using new with bounds or initializers
– SingleDim = new int[20];
– TwoDim = new int[,]{{1,2,3},{4,5,6}};
– Jagged = new int[1][ ];
Jagged[0] = new int[ ]{1,2,3};
Statements and Comments
= assignment
+ addition
- subtraction
* multiplication
/ division
% modulus
++ increment by one
-- decrement by one
strings
• Immutable sequence of Unicode
characters (char)
• Creation:
– string s = “Bob”;
– string s = new String(“Bob”);
• Backslash is an escape:
– Newline: “\n”
– Tab: “\t”
string/int conversions
• string to numbers:
– int i = int.Parse(“12345”);
– float f = float.Parse(“123.45”);
• Numbers to strings:
– string msg = “Your number is ” + 123;
– string msg = “It costs ” +
string.Format(“{0:C}”, 1.23);
Arrays
• (page 21 of quickstart handout)
• Derived from System.Array
• Use square brackets []
• Zero-based
• Static size
• Initialization:
– int [ ] nums;
– int [ ] nums = new int[3]; // 3 items
– int [ ] nums = new int[ ] {10, 20, 30};
Arrays Final
• Multidimensional
// 3 rows, 2 columns
int [ , ] myMultiIntArray = new int[3,2]
== equals
!= not equals
&& and
|| or
If, Case Statements
while (condition)
{
statements;
}
Class clsName
{
modifier dataType varName;
modifier returnType methodName (params)
{
statements;
return returnVal;
}
}
Hello World
namespace Sample
{
using System;
while(true) ;
}
}
}
Summary
• C# builds on the .NET Framework component
model
• New language with familiar structure
– Easy to adopt for developers of C, C++, Java, and
Visual Basic applications
• Fully object oriented
• Optimized for the .NET Framework
ASP .Net and C#
• Easily combined and ready to be used
in WebPages.
• Powerful
• Fast
• Most of the works are done without
getting stuck in low level programming
and driver fixing and …
An ASP.Net Simple Start
End of The C#