SlideShare a Scribd company logo
1 of 25
Download to read offline
MSP Monday
Date: May 26, 2014
C#
Basic to Intermediate
Part 1
Presentedby ZaforIqbal
zafor.iqbal@outlook.com
Target Audience
This Lecture has been prepared for the beginners who has basic
understanding of object oriented programming or Java.
Environment Setup
What do we need?
• A Windows PC
• Visual Studio 2010/2012/2013
• Lots of passion to code!
Introduction
What is C Sharp(C#)?
C# is a simple, modern, general-purpose, object-oriented
programming language developed by Microsoft within its .NET
initiative led by Anders Hejlsberg.
Anders Hejlsberg
Basic Syntax
Hello World Example in C#
using System;
namespace HelloWorldApplication {
class HelloWorld {
static void Main(string[] args) {
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadLine();
}
}
}
Data Types
In C#, variables are categorized into the following types:
 Value types; i.e. bool, byte, char, decimal,double etc.
 Reference types;
Object type; i.e. object obj=50; Dynamic type; dynamic d= 400;
String type; i.e. String str = “MSP Monday”;
 Pointer types: Pointer type variables store the memory address of another type.
Pointers in C# have the same capabilities as in C or C++.
i.e. char* ch; int* inr;
Type Conversion
Implicit type conversion - these conversions are performed by C# in a type-
safe manner.
Examples : conversions from smaller to larger integral types and conversions
from derived classes to base classes.
Explicit type conversion - these conversions are done explicitly by users using
the pre-defined functions. Explicit conversions require a cast operator.
Type Conversion Examples
namespace TypeConversionApplication{
class ExplicitConversion {
static void Main(string[] args){
double d = 5673.74;
int i;
i = (int)d; // cast double to int.
Console.WriteLine(i);
Console.ReadKey();
}
}
}
Variables
A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in C# has a specific type, which determines the size
and layout of the variable's memory; the range of values that can be stored
within that memory; and the set of operations that can be applied to the
variable.
Syntax for variable definition in C# is:
<data_type> <variable_name> = value;
i.e. double pi = 3.14159;
Constants and Literals
 The constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals. Constants can be of any
of the basic data types like an integer constant, a floating constant, a
character constant, or a string literal. There are also enumeration constants
as well.
 The constants are treated just like regular variables except that their values
cannot be modified after their definition.
Example
using System;
namespace DeclaringConstants{
class Program {
static void Main(string[] args){
const double pi = 3.14159; // constant declaration
double r;
Console.WriteLine("Enter Radius: ");
r = Convert.ToDouble(Console.ReadLine());
double areaCircle = pi * r * r;
Console.WriteLine("Radius: {0}, Area: {1}", r, areaCircle);
Console.ReadLine();
}
}
}
Operators
An operator is a symbol that tells the compiler to perform specific mathematical or
logical manipulations. C# is rich in built-in operators and provides the following type of
operators:
 Arithmetic Operators; i.e. +,-,*,/,% etc.
 Relational Operators; i.e. ==,!=,>,<,>=,<= etc.
 Logical Operators; i.e. &&, ||, ! etc.
 Bitwise Operators; i.e. &,|,^ etc.
 Assignment Operators; i.e. =,+=.-=;*= etc.
 Misc Operators; i.e. sizeof(),typeof(),is,as etc.
Conditional Statements
LOOP
The Infinite Loop?
using System;
namespace Loops{
class Program{
static void Main(string[] args)
{
for ( ; ; )
{
Console.WriteLine(“Yo, is this ever gonna end?");
}
}
}
}
Encapsulation
 Encapsulation is defined 'as the process of enclosing one or more items
within a physical or logical package'. Encapsulation, in object oriented
programming methodology, prevents access to implementation details.
 Encapsulation is implemented by using access specifiers. An access specifier defines the scope
and visibility of a class member. C# supports the following access specifiers:
 Public
 Private
 Protected
 Internal
 Protected internal
Encapsulation
 Public : Any public member can be accessed from outside the class.
 Private : Private access specifier allows a class to hide its member variables and member functions
from other functions and objects. Only functions of the same class can access its private members.
Even an instance of a class cannot access its private members.
 Protected : Protected access specifier allows a child class to access the member variables and member
functions of its base class. This way it helps in implementing inheritance.
 Internal : Internal access specifier allows a class to expose its member variables and member functions
to other functions and objects in the current assembly. In other words, any member with internal
access specifier can be accessed from any class or method defined within the application in which the
member is defined.
 Protected internal : The protected internal access specifier allows a class to hide its member variables
and member functions from other class objects and functions, except a child class within the same
application. This is also used while implementing inheritance.
Arrays
An array stores a fixed-size sequential collection of elements of the same
type. An array is used to store a collection of data, but it is often more useful
to think of an array as a collection of variables of the same type.
 Initializing an Array
double[] balance = new double[10];
 Assigning Values to an Array
double[] balance = new double[10];
balance[0] = 4500.0;
String
In C#, you can use strings as array of characters, however, more common
practice is to use the string keyword to declare a string variable. The string
keyword is an alias for the System.String class.
Creating a String Object
You can create string object using one of the following methods:
 By assigning a string literal to a String variable
 By using a String class constructor
 By using the string concatenation operator (+)
 By retrieving a property or calling a method that returns a string
 By calling a formatting method to convert a value or object to its string representation
Example
using System;
namespace StringApplication
{ class Program
{ static void Main(string[] args)
{
//from string literal and string concatenation
string fname, lname;
fname = “MSP";
lname = “Monday";
string fullname = fname + lname;
Console.WriteLine("Full Name: {0}", fullname);
Example Continued
//by using string constructor
char[] letters = { 'H', 'e', 'l', 'l','o' };
string greetings = new string(letters);
Console.WriteLine("Greetings: {0}", greetings);
//methods returning string
string[] sarray = { "Hello", "From", “MSP", “Monday" };
string message = String.Join(" ", sarray);
Console.WriteLine("Message: {0}", message);
Example Continued
//formatting method to convert a value
DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1);
string chat = String.Format("Message sent at {0:t} on {0:D}",
waiting);
Console.WriteLine("Message: {0}", chat);
Console.ReadKey() ;
}
}
}
That’s it for today!
We will resume from next Session!
Thank you
C Sharp: Basic to Intermediate Part 01

More Related Content

What's hot

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 

What's hot (20)

Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
class and objects
class and objectsclass and objects
class and objects
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 

Similar to C Sharp: Basic to Intermediate Part 01

Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
 

Similar to C Sharp: Basic to Intermediate Part 01 (20)

OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
C#ppt
C#pptC#ppt
C#ppt
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
My c++
My c++My c++
My c++
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Recently uploaded (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

C Sharp: Basic to Intermediate Part 01

  • 2. C# Basic to Intermediate Part 1 Presentedby ZaforIqbal zafor.iqbal@outlook.com
  • 3. Target Audience This Lecture has been prepared for the beginners who has basic understanding of object oriented programming or Java.
  • 4. Environment Setup What do we need? • A Windows PC • Visual Studio 2010/2012/2013 • Lots of passion to code!
  • 5. Introduction What is C Sharp(C#)? C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. Anders Hejlsberg
  • 6. Basic Syntax Hello World Example in C# using System; namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadLine(); } } }
  • 7. Data Types In C#, variables are categorized into the following types:  Value types; i.e. bool, byte, char, decimal,double etc.  Reference types; Object type; i.e. object obj=50; Dynamic type; dynamic d= 400; String type; i.e. String str = “MSP Monday”;  Pointer types: Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as in C or C++. i.e. char* ch; int* inr;
  • 8. Type Conversion Implicit type conversion - these conversions are performed by C# in a type- safe manner. Examples : conversions from smaller to larger integral types and conversions from derived classes to base classes. Explicit type conversion - these conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.
  • 9. Type Conversion Examples namespace TypeConversionApplication{ class ExplicitConversion { static void Main(string[] args){ double d = 5673.74; int i; i = (int)d; // cast double to int. Console.WriteLine(i); Console.ReadKey(); } } }
  • 10. Variables A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. Syntax for variable definition in C# is: <data_type> <variable_name> = value; i.e. double pi = 3.14159;
  • 11. Constants and Literals  The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.  The constants are treated just like regular variables except that their values cannot be modified after their definition.
  • 12. Example using System; namespace DeclaringConstants{ class Program { static void Main(string[] args){ const double pi = 3.14159; // constant declaration double r; Console.WriteLine("Enter Radius: "); r = Convert.ToDouble(Console.ReadLine()); double areaCircle = pi * r * r; Console.WriteLine("Radius: {0}, Area: {1}", r, areaCircle); Console.ReadLine(); } } }
  • 13. Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C# is rich in built-in operators and provides the following type of operators:  Arithmetic Operators; i.e. +,-,*,/,% etc.  Relational Operators; i.e. ==,!=,>,<,>=,<= etc.  Logical Operators; i.e. &&, ||, ! etc.  Bitwise Operators; i.e. &,|,^ etc.  Assignment Operators; i.e. =,+=.-=;*= etc.  Misc Operators; i.e. sizeof(),typeof(),is,as etc.
  • 15. LOOP
  • 16. The Infinite Loop? using System; namespace Loops{ class Program{ static void Main(string[] args) { for ( ; ; ) { Console.WriteLine(“Yo, is this ever gonna end?"); } } } }
  • 17. Encapsulation  Encapsulation is defined 'as the process of enclosing one or more items within a physical or logical package'. Encapsulation, in object oriented programming methodology, prevents access to implementation details.  Encapsulation is implemented by using access specifiers. An access specifier defines the scope and visibility of a class member. C# supports the following access specifiers:  Public  Private  Protected  Internal  Protected internal
  • 18. Encapsulation  Public : Any public member can be accessed from outside the class.  Private : Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.  Protected : Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance.  Internal : Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.  Protected internal : The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application. This is also used while implementing inheritance.
  • 19. Arrays An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.  Initializing an Array double[] balance = new double[10];  Assigning Values to an Array double[] balance = new double[10]; balance[0] = 4500.0;
  • 20. String In C#, you can use strings as array of characters, however, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class. Creating a String Object You can create string object using one of the following methods:  By assigning a string literal to a String variable  By using a String class constructor  By using the string concatenation operator (+)  By retrieving a property or calling a method that returns a string  By calling a formatting method to convert a value or object to its string representation
  • 21. Example using System; namespace StringApplication { class Program { static void Main(string[] args) { //from string literal and string concatenation string fname, lname; fname = “MSP"; lname = “Monday"; string fullname = fname + lname; Console.WriteLine("Full Name: {0}", fullname);
  • 22. Example Continued //by using string constructor char[] letters = { 'H', 'e', 'l', 'l','o' }; string greetings = new string(letters); Console.WriteLine("Greetings: {0}", greetings); //methods returning string string[] sarray = { "Hello", "From", “MSP", “Monday" }; string message = String.Join(" ", sarray); Console.WriteLine("Message: {0}", message);
  • 23. Example Continued //formatting method to convert a value DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1); string chat = String.Format("Message sent at {0:t} on {0:D}", waiting); Console.WriteLine("Message: {0}", chat); Console.ReadKey() ; } } }
  • 24. That’s it for today! We will resume from next Session! Thank you