SlideShare a Scribd company logo
1 of 101
C# Language Overview (Part II) Creating and Using Objects, Exceptions, Strings, Generics, Collections, Attributes Doncho Minkov Telerik School Academy schoolacademy.telerik.com   Technical Trainer http://www.minkov.it
Table of Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Classes and Objects Using the Standard .NET Framework Classes
What is Class? ,[object Object],[object Object],Classes  act as templates from which an instance of an object is created at run time. Classes define the properties of the object and the methods used to control the object's behavior.
Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes – Example Account +Owner: Person +Ammount: double +Suspend() +Deposit(sum:double) +Withdraw(sum:double) Class Name Attributes (Properties and Fields) Operations (Methods)
Objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Objects – Example Account +Owner: Person +Ammount: double +Suspend() +Deposit(sum:double) +Withdraw(sum:double) Class ivanAccount +Owner="Ivan Kolev" +Ammount=5000.0 peterAccount +Owner="Peter Kirov" +Ammount=1825.33 kirilAccount +Owner="Kiril Kirov" +Ammount=25.0 Object Object Object
Classes in C# ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes in C# – Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Declaring Objects ,[object Object],[object Object],using System; ... // Define two variables of type DateTime DateTime today;  DateTime halloween; // Declare and initialize a structure instance DateTime today = DateTime.Now;
Fields ,[object Object],[object Object],[object Object],[object Object],[object Object]
Accessing Fields ,[object Object],[object Object],[object Object],[object Object],// Accessing read-only field String empty = String.Empty; // Accessing constant field int maxInt = Int32.MaxValue;
Properties ,[object Object],[object Object],[object Object],[object Object],[object Object]
Properties (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Accessing Properties and Fields – Example using System; ... DateTime christmas = new DateTime(2009, 12, 25); int day = christmas.Day; int month = christmas.Month; int year = christmas.Year; Console.WriteLine( "Christmas day: {0}, month: {1}, year: {2}", day, month, year); Console.WriteLine( "Day of year: {0}", christmas.DayOfYear); Console.WriteLine("Is {0} leap year: {1}", year, DateTime.IsLeapYear(year));
Instance and Static Members ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Instance and Static Members – Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Instance Methods ,[object Object],[object Object],[object Object],[object Object],<object_name>.<method_name>(<parameters>)
Calling Instance Methods –  Examples ,[object Object],[object Object],String sampleLower = new String('a', 5); String sampleUpper = sampleLower.ToUpper(); Console.WriteLine(sampleLower); // aaaaa Console.WriteLine(sampleUpper); // AAAAA DateTime now = DateTime.Now; DateTime later = now.AddHours(8); Console.WriteLine(&quot;Now: {0}&quot;, now); Console.WriteLine(&quot;8 hours later: {0}&quot;, later);
Static Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],<class_name>.<method_name>(<parameters>)
Calling Static Methods – Examples using System; double radius = 2.9; double area = Math.PI * Math.Pow(radius, 2); Console.WriteLine(&quot;Area: {0}&quot;, area); // Area: 26,4207942166902 double precise = 8.7654321; double round3 = Math.Round(precise, 3); double round1 = Math.Round(precise, 1); Console.WriteLine( &quot;{0}; {1}; {2}&quot;, precise, round3, round1); // 8,7654321; 8,765; 8,8 Constant field Static method Static method Static method
Constructors ,[object Object],[object Object],[object Object],[object Object],[object Object]
Constructors (2) ,[object Object],[object Object],String s = new String(&quot;Hello!&quot;); // s = &quot;Hello!&quot; <instance_name> = new <class_name>(<parameters>) String s = new String('*', 5); // s = &quot;*****&quot; DateTime dt = new DateTime(2009, 12, 30); DateTime dt = new DateTime(2009, 12, 30, 12, 33, 59); Int32 value = new Int32(1024);
Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is a Namespace? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Full Class Names ,[object Object],[object Object],[object Object],[object Object],<namespace_name>.<class_name>
Including Namespaces ,[object Object],[object Object],[object Object],[object Object],using <namespace_name> using System; DateTime date; System.DateTime date;
Common Type System (CTS) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CTS and Different Languages ,[object Object],[object Object],[object Object],CTS Type C# Type VB.NET Type System.Int32 int Integer System.Single float Single System.Boolean bool Boolean System.String string String System.Object object Object
Value and Reference Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Value and Reference Types – Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exceptions Handling The Paradigm of Exceptions in OOP
What are Exceptions? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Handling Exceptions ,[object Object],[object Object],try { // Do some work that can raise an exception } catch (SomeException) { // Handle the caught exception }
Handling Exceptions – Example static void Main() { string s = Console.ReadLine(); try { Int32.Parse(s); Console.WriteLine( &quot;You entered valid Int32 number {0}.&quot;, s); } catch  (FormatException) { Console.WriteLine(&quot;Invalid integer number!&quot;); } catch  (OverflowException) { Console.WriteLine( &quot;The number is too big to fit in Int32!&quot;); } }
The   System.Exception  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exception Properties – Example class ExceptionsTest { public static void CauseFormatException() { string s = &quot;an invalid number&quot;; Int32.Parse(s); } static void Main() { try { CauseFormatException(); } catch (FormatException fe) { Console.Error.WriteLine(&quot;Exception caught:   {0}{1}&quot;, fe.Message, fe.StackTrace); } } }
Exception Properties ,[object Object],[object Object],Exception caught: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) at ExceptionsTest.CauseFormatException() in c:onsoleapplication1xceptionstest.cs:line 8 at ExceptionsTest.Main(String[] args) in c:onsoleapplication1xceptionstest.cs:line 15
Exception Properties (2) ,[object Object],[object Object],Exception caught: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at ExceptionsTest.Main(String[] args)
Exception Hierarchy ,[object Object]
Types of Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Handling Exceptions ,[object Object],[object Object],[object Object],try { // Do some works that can raise an exception } catch (System.ArithmeticException) { // Handle the caught arithmetic exception }
Handling All Exceptions ,[object Object],[object Object],[object Object],try { // Do some works that can raise any exception } catch { // Handle the caught exception }
Throwing Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How Exceptions Work? Main() Method 1 Method 2 Method N 2. Method call 3. Method call 4. Method call … Main() Method 1 Method 2 Method N 8. Find handler 7. Find handler 6. Find handler … 5. Throw an exception .NET CLR 1. Execute the program 9. Find handler 10. Display error message
Using  throw  Keyword ,[object Object],[object Object],[object Object],throw new ArgumentException(&quot;Invalid amount!&quot;); try { Int32.Parse(str); } catch (FormatException fe) { throw new ArgumentException(&quot;Invalid number&quot;, fe); }
Throwing Exceptions – Example public static double Sqrt(double value) { if (value < 0) throw new System.ArgumentOutOfRangeException( &quot;Sqrt for negative numbers is undefined!&quot;); return Math.Sqrt(value); } static void Main() { try { Sqrt(-1); } catch (ArgumentOutOfRangeException ex) { Console.Error.WriteLine(&quot;Error: &quot; + ex.Message); throw; } }
Strings and Text Processing
What Is String? ,[object Object],[object Object],[object Object],[object Object],string s = &quot;Hello, C#&quot;; s H e l l o , C #
The  System.String  Class ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  System.String  Class (2) ,[object Object],[object Object],[object Object],[object Object],string s = &quot;Hello!&quot;; int len = s.Length; // len = 6 char ch = s[1]; // ch = 'e' index  =  s[index]  =  0 1 2 3 4 5 H e l l o !
Strings – Example static void Main() { string s =  &quot;Stand up, stand up, Balkan Superman.&quot;; Console.WriteLine(&quot;s = amp;quot;{0}amp;quot;&quot;, s); Console.WriteLine(&quot;s.Length = {0}&quot;, s.Length); for (int i = 0; i < s.Length; i++) { Console.WriteLine(&quot;s[{0}] = {1}&quot;, i, s[i]); } }
Declaring Strings ,[object Object],[object Object],[object Object],[object Object],string str1; System.String str2; String str3;
Creating Strings ,[object Object],[object Object],[object Object],[object Object],[object Object]
Creating Strings (2) ,[object Object],[object Object],[object Object],[object Object],string s; // s is equal to null string s = &quot;I am a string literal!&quot;; string s2 = s; string s = 42.ToString();
Reading and Printing Strings ,[object Object],[object Object],string s = Console.ReadLine(); Console.Write(&quot;Please enter your name: &quot;);  string name = Console.ReadLine(); Console.Write(&quot;Hello, {0}! &quot;, name); Console.WriteLine(&quot;Welcome to our party!&quot;); ,[object Object],[object Object]
Comparing Strings ,[object Object],[object Object],[object Object],[object Object],int result = string.Compare(str1, str2, true); // result == 0 if str1 equals str2 // result < 0 if str1 if before str2 // result > 0 if str1 if after str2 string.Compare(str1, str2, false);
Comparing Strings – Example  ,[object Object],string[] towns = {&quot;Sofia&quot;, &quot;Varna&quot;, &quot;Plovdiv&quot;, &quot;Pleven&quot;, &quot;Bourgas&quot;, &quot;Rousse&quot;, &quot;Yambol&quot;}; string firstTown = towns[0]; for (int i=1; i<towns.Length; i++) { string currentTown = towns[i]; if (String.Compare(currentTown, firstTown) < 0) { firstTown = currentTown; } } Console.WriteLine(&quot;First town: {0}&quot;, firstTown);
Concatenating Strings ,[object Object],[object Object],[object Object],[object Object],string str = String.Concat(str1, str2);  string str = str1 + str2 + str3; string str += str1; string name = &quot;Peter&quot;; int age = 22; string s = name + &quot; &quot; + age; //    &quot;Peter 22&quot;
Searching in Strings ,[object Object],[object Object],[object Object],[object Object],IndexOf(string str) IndexOf(string str, int startIndex) LastIndexOf(string)
Searching in Strings – Example string str = &quot;C# Programming Course&quot;; int index = str.IndexOf(&quot;C#&quot;); // index = 0 index = str.IndexOf(&quot;Course&quot;); // index = 15 index = str.IndexOf(&quot;COURSE&quot;); // index = -1 // IndexOf is case-sensetive. -1 means not found index = str.IndexOf(&quot;ram&quot;); // index = 7 index = str.IndexOf(&quot;r&quot;); // index = 4 index = str.IndexOf(&quot;r&quot;, 5); // index = 7 index = str.IndexOf(&quot;r&quot;, 8); // index = 18 index  =  s[index]  =  0 1 2 3 4 5 6 7 8 9 10 11 12 13 … C # P r o g r a m m i n g …
Extracting Substrings ,[object Object],[object Object],[object Object],string filename = @&quot;C:icsila2009.jpg&quot;; string name = filename.Substring(8, 8); // name is Rila2009 string filename = @&quot;C:icsummer2009.jpg&quot;; string nameAndExtension = filename.Substring(8); // nameAndExtension is Summer2009.jpg 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 C :  P i c s R i l a 2 0 0 5 . j p g
Splitting Strings ,[object Object],[object Object],string[] Split(params char[]) string listOfBeers = &quot;Amstel, Zagorka, Tuborg, Becks.&quot;; string[] beers =  listOfBeers.Split(' ', ',', '.'); Console.WriteLine(&quot;Available beers are:&quot;); foreach (string beer in beers) { Console.WriteLine(beer); }
Replacing and Deleting Substrings ,[object Object],[object Object],[object Object],string cocktail = &quot;Vodka + Martini + Cherry&quot;; string replaced = cocktail.Replace(&quot;+&quot;, &quot;and&quot;); // Vodka and Martini and Cherry string price = &quot;$ 1234567&quot;; string lowPrice = price.Remove(2, 3); // $ 4567
Changing Character Casing ,[object Object],[object Object],string alpha = &quot;aBcDeFg&quot;; string lowerAlpha = alpha.ToLower(); // abcdefg Console.WriteLine(lowerAlpha); string alpha = &quot;aBcDeFg&quot;; string upperAlpha = alpha.ToUpper(); // ABCDEFG Console.WriteLine(upperAlpha);
Trimming White Space ,[object Object],[object Object],[object Object],string s = &quot;  example of white space  &quot;; string clean = s.Trim(); Console.WriteLine(clean); string s = &quot; Hello!!! &quot;; string clean = s.Trim(' ', ',' ,'!', '',''); Console.WriteLine(clean); // Hello string s = &quot;  C#  &quot;; string clean = s.TrimStart(); // clean = &quot;C#  &quot;
Constructing Strings ,[object Object],[object Object],[object Object],[object Object],public static string DupChar(char ch, int count) { string result = &quot;&quot;; for (int i=0; i<count; i++) result += ch; return result; } Very bad practice. Avoid this!
Changing the Contents of a String –  StringBuilder ,[object Object],[object Object],public static string ReverseString(string s) { StringBuilder sb = new StringBuilder(); for (int i = s.Length-1; i >= 0; i--) sb.Append(s[i]); return sb.ToString(); }
The  StringBuilde r Class ,[object Object],[object Object],[object Object],[object Object],[object Object],Capacity used buffer ( Length ) unused buffer H e l l o , C # !
StringBuilder  – Example ,[object Object],public static string ExtractCapitals(string s) { StringBuilder result = new StringBuilder(); for (int i = 0; i<s.Length; i++)  {   if (Char.IsUpper(s[i])) { result.Append(s[i]); } } return result.ToString(); }
Method  ToString() ,[object Object],[object Object],[object Object],[object Object],int number = 5; string s = &quot;The number is &quot; + number.ToString(); Console.WriteLine(s); // The number is 5
Method  ToString(format ) ,[object Object],[object Object],int number = 42; string s = number.ToString(&quot;D5&quot;); // 00042 s = number.ToString(&quot;X&quot;); // 2A // Consider the default culture is Bulgarian s = number.ToString(&quot;C&quot;); // 42,00 лв double d = 0.375; s = d.ToString(&quot;P2&quot;); // 37,50 %
Formatting Strings ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Method  String.Format() ,[object Object],[object Object],[object Object],string template = &quot;If I were {0}, I would {1}.&quot;; string sentence1 = String.Format( template, &quot;developer&quot;, &quot;know C#&quot;); Console.WriteLine(sentence1); // If I were developer, I would know C#. string sentence2 = String.Format( template, &quot;elephant&quot;, &quot;weigh 4500 kg&quot;); Console.WriteLine(sentence2); // If I were elephant, I would weigh 4500 kg.
Composite Formatting ,[object Object],[object Object],{index[,alignment][:formatString]} double d = 0.375; s = String.Format(&quot;{0,10:F5}&quot;, d); // s = &quot;  0,37500&quot; int number = 42; Console.WriteLine(&quot;Dec {0:D} = Hex {1:X}&quot;, number, number); // Dec 42 = Hex 2A
Formatting Dates ,[object Object],[object Object],[object Object],[object Object],[object Object],DateTime now = DateTime.Now; Console.WriteLine( &quot;Now is {0:d.MM.yyyy HH:mm:ss}&quot;, now); // Now is 31.11.2009 11:30:32
Collection Classes Lists, Trees, Dictionaries
What are Generics? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  List<T>  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
List<T>  – Simple Example static void Main() { List<string> list = new List<string>(); list.Add(&quot;C#&quot;); list.Add(&quot;Java&quot;); list.Add(&quot;PHP&quot;); foreach (string item in list) { Console.WriteLine(item); } // Result: //  C# //  Java //  PHP }
List<T>  – Functionality ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
List<T>  – Functionality (2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Primes in an Interval – Example static List<int> FindPrimes(int start, int end) { List<int> primesList = new List<int>(); for (int num = start; num <= end; num++) { bool prime = true; for (int div = 2; div <= Math.Sqrt(num); div++) { if (num % div == 0) { prime = false; break; } } if (prime) { primesList.Add(num); } } return primesList; }
The  Stack<T>  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stack<T>  – Example ,[object Object],static void Main() { Stack<string> stack = new Stack<string>(); stack.Push(&quot;1. Ivan&quot;); stack.Push(&quot;2. Nikolay&quot;); stack.Push(&quot;3. Maria&quot;); stack.Push(&quot;4. George&quot;); Console.WriteLine(&quot;Top = {0}&quot;, stack.Peek()); while (stack.Count > 0) { string personName = stack.Pop(); Console.WriteLine(personName); } }
The  Queue<T>  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Queue<T>  –   Example ,[object Object],static void Main() { Queue<string> queue = new Queue<string>(); queue.Enqueue(&quot;Message One&quot;); queue.Enqueue(&quot;Message Two&quot;); queue.Enqueue(&quot;Message Three&quot;); queue.Enqueue(&quot;Message Four&quot;); while (queue.Count > 0) { string message = queue.Dequeue(); Console.WriteLine(message); } }
Dictionary<TKey,TValue>   Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dictionary<TKey,TValue>  Class (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dictionary<TKey,TValue>  Class (3) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dictionary<TKey,Tvalue>  –  Example Dictionary<string, int> studentsMarks    = new Dictionary<string, int>(); studentsMarks.Add(&quot;Ivan&quot;, 4); studentsMarks.Add(&quot;Peter&quot;, 6); studentsMarks.Add(&quot;Maria&quot;, 6); studentsMarks.Add(&quot;George&quot;, 5); int peterMark = studentsMarks[&quot;Peter&quot;]; Console.WriteLine(&quot;Peter's mark: {0}&quot;, peterMark); Console.WriteLine(&quot;Is Peter in the hash table: {0}&quot;, studentsMarks.ContainsKey(&quot;Peter&quot;)); Console.WriteLine(&quot;Students and grades:&quot;); foreach (var pair in studentsMarks) { Console.WriteLine(&quot;{0} --> {1} &quot;, pair.Key, pair.Value); }
Counting Words in Given Text string text = &quot;Welcome to our C# course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in C# and Microsoft .NET&quot;; string[] words = text.Split(new char[] {' ', ',', '.'}, StringSplitOptions.RemoveEmptyEntries); var wordsCount = new Dictionary<string, int>(); foreach (string word in words) { if (wordsCount.ContainsKey(word)) wordsCount[word]++; else wordsCount.Add(word, 1); } foreach (var pair in wordsCount) { Console.WriteLine(&quot;{0} --> {1}&quot;, pair.Key, pair.Value); }
Balanced Trees in .NET ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sorted Dictionary – Example  string text = &quot;Welcome to our C# course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in C# and Microsoft .NET&quot;; string[] words = text.Split(new char[] {' ', ',', '.'}, StringSplitOptions.RemoveEmptyEntries); var wordsCount = new SortedDictionary<string, int>(); foreach (string word in words) { if (wordsCount.ContainsKey(word)) wordsCount[word]++; else wordsCount.Add(word, 1); } foreach (var pair in wordsCount) { Console.WriteLine(&quot;{0} --> {1}&quot;, pair.Key, pair.Value); }
Attributes What They Are? How and When to Use Them?
What Are Attributes? ,[object Object],[object Object],[object Object],[object Object]
Attributes Applying – Example ,[object Object],[object Object],[Flags] // System.FlagsAttribute public enum FileAccess  { Read = 1, Write = 2, ReadWrite = Read | Write }
Attributes With Parameters ,[object Object],[object Object],[object Object],[DllImport(&quot;user32.dll&quot;, EntryPoint=&quot;MessageBox&quot;)] public static extern int ShowMessageBox(int hWnd, string text, string caption, int type); ... ShowMessageBox(0, &quot;Some text&quot;, &quot;Some caption&quot;, 0);
C# Language Overview (Part II) ,[object Object],http://academy.telerik.com

More Related Content

What's hot

Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3mohamedsamyali
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
javaimplementation
javaimplementationjavaimplementation
javaimplementationFaRaz Ahmad
 
Option - A Better Way to Handle Null Value
Option - A Better Way to Handle Null ValueOption - A Better Way to Handle Null Value
Option - A Better Way to Handle Null ValueJiaming Zhang
 
Ios development
Ios developmentIos development
Ios developmentelnaqah
 
The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189Mahmoud Samir Fayed
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from javaIndicThreads
 
Python oop - class 2 (inheritance)
Python   oop - class 2 (inheritance)Python   oop - class 2 (inheritance)
Python oop - class 2 (inheritance)Aleksander Fabijan
 

What's hot (20)

Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Core java
Core javaCore java
Core java
 
Object and class
Object and classObject and class
Object and class
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
javaimplementation
javaimplementationjavaimplementation
javaimplementation
 
Option - A Better Way to Handle Null Value
Option - A Better Way to Handle Null ValueOption - A Better Way to Handle Null Value
Option - A Better Way to Handle Null Value
 
Ios development
Ios developmentIos development
Ios development
 
The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189The Ring programming language version 1.6 book - Part 182 of 189
The Ring programming language version 1.6 book - Part 182 of 189
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Python oop class 1
Python oop   class 1Python oop   class 1
Python oop class 1
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
Java
Java Java
Java
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Python oop - class 2 (inheritance)
Python   oop - class 2 (inheritance)Python   oop - class 2 (inheritance)
Python oop - class 2 (inheritance)
 
Python - OOP Programming
Python - OOP ProgrammingPython - OOP Programming
Python - OOP Programming
 
Core java concepts
Core java conceptsCore java concepts
Core java concepts
 

Similar to C# Language Overview Part II

Similar to C# Language Overview Part II (20)

Using class and object java
Using class and object javaUsing class and object java
Using class and object java
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
C# program structure
C# program structureC# program structure
C# program structure
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 

More from Doncho Minkov

More from Doncho Minkov (20)

Web Design Concepts
Web Design ConceptsWeb Design Concepts
Web Design Concepts
 
Web design Tools
Web design ToolsWeb design Tools
Web design Tools
 
HTML 5
HTML 5HTML 5
HTML 5
 
HTML 5 Tables and Forms
HTML 5 Tables and FormsHTML 5 Tables and Forms
HTML 5 Tables and Forms
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
CSS Presentation
CSS PresentationCSS Presentation
CSS Presentation
 
CSS Layout
CSS LayoutCSS Layout
CSS Layout
 
CSS 3
CSS 3CSS 3
CSS 3
 
Adobe Photoshop
Adobe PhotoshopAdobe Photoshop
Adobe Photoshop
 
Slice and Dice
Slice and DiceSlice and Dice
Slice and Dice
 
Introduction to XAML and WPF
Introduction to XAML and WPFIntroduction to XAML and WPF
Introduction to XAML and WPF
 
WPF Layout Containers
WPF Layout ContainersWPF Layout Containers
WPF Layout Containers
 
WPF Controls
WPF ControlsWPF Controls
WPF Controls
 
WPF Templating and Styling
WPF Templating and StylingWPF Templating and Styling
WPF Templating and Styling
 
WPF Graphics and Animations
WPF Graphics and AnimationsWPF Graphics and Animations
WPF Graphics and Animations
 
Simple Data Binding
Simple Data BindingSimple Data Binding
Simple Data Binding
 
Complex Data Binding
Complex Data BindingComplex Data Binding
Complex Data Binding
 
WPF Concepts
WPF ConceptsWPF Concepts
WPF Concepts
 
Model View ViewModel
Model View ViewModelModel View ViewModel
Model View ViewModel
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 

Recently uploaded

Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

C# Language Overview Part II

  • 1. C# Language Overview (Part II) Creating and Using Objects, Exceptions, Strings, Generics, Collections, Attributes Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer http://www.minkov.it
  • 2.
  • 3. Using Classes and Objects Using the Standard .NET Framework Classes
  • 4.
  • 5.
  • 6. Classes – Example Account +Owner: Person +Ammount: double +Suspend() +Deposit(sum:double) +Withdraw(sum:double) Class Name Attributes (Properties and Fields) Operations (Methods)
  • 7.
  • 8. Objects – Example Account +Owner: Person +Ammount: double +Suspend() +Deposit(sum:double) +Withdraw(sum:double) Class ivanAccount +Owner=&quot;Ivan Kolev&quot; +Ammount=5000.0 peterAccount +Owner=&quot;Peter Kirov&quot; +Ammount=1825.33 kirilAccount +Owner=&quot;Kiril Kirov&quot; +Ammount=25.0 Object Object Object
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Accessing Properties and Fields – Example using System; ... DateTime christmas = new DateTime(2009, 12, 25); int day = christmas.Day; int month = christmas.Month; int year = christmas.Year; Console.WriteLine( &quot;Christmas day: {0}, month: {1}, year: {2}&quot;, day, month, year); Console.WriteLine( &quot;Day of year: {0}&quot;, christmas.DayOfYear); Console.WriteLine(&quot;Is {0} leap year: {1}&quot;, year, DateTime.IsLeapYear(year));
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. Calling Static Methods – Examples using System; double radius = 2.9; double area = Math.PI * Math.Pow(radius, 2); Console.WriteLine(&quot;Area: {0}&quot;, area); // Area: 26,4207942166902 double precise = 8.7654321; double round3 = Math.Round(precise, 3); double round1 = Math.Round(precise, 1); Console.WriteLine( &quot;{0}; {1}; {2}&quot;, precise, round3, round1); // 8,7654321; 8,765; 8,8 Constant field Static method Static method Static method
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. Exceptions Handling The Paradigm of Exceptions in OOP
  • 35.
  • 36.
  • 37. Handling Exceptions – Example static void Main() { string s = Console.ReadLine(); try { Int32.Parse(s); Console.WriteLine( &quot;You entered valid Int32 number {0}.&quot;, s); } catch (FormatException) { Console.WriteLine(&quot;Invalid integer number!&quot;); } catch (OverflowException) { Console.WriteLine( &quot;The number is too big to fit in Int32!&quot;); } }
  • 38.
  • 39. Exception Properties – Example class ExceptionsTest { public static void CauseFormatException() { string s = &quot;an invalid number&quot;; Int32.Parse(s); } static void Main() { try { CauseFormatException(); } catch (FormatException fe) { Console.Error.WriteLine(&quot;Exception caught: {0}{1}&quot;, fe.Message, fe.StackTrace); } } }
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. How Exceptions Work? Main() Method 1 Method 2 Method N 2. Method call 3. Method call 4. Method call … Main() Method 1 Method 2 Method N 8. Find handler 7. Find handler 6. Find handler … 5. Throw an exception .NET CLR 1. Execute the program 9. Find handler 10. Display error message
  • 48.
  • 49. Throwing Exceptions – Example public static double Sqrt(double value) { if (value < 0) throw new System.ArgumentOutOfRangeException( &quot;Sqrt for negative numbers is undefined!&quot;); return Math.Sqrt(value); } static void Main() { try { Sqrt(-1); } catch (ArgumentOutOfRangeException ex) { Console.Error.WriteLine(&quot;Error: &quot; + ex.Message); throw; } }
  • 50. Strings and Text Processing
  • 51.
  • 52.
  • 53.
  • 54. Strings – Example static void Main() { string s = &quot;Stand up, stand up, Balkan Superman.&quot;; Console.WriteLine(&quot;s = amp;quot;{0}amp;quot;&quot;, s); Console.WriteLine(&quot;s.Length = {0}&quot;, s.Length); for (int i = 0; i < s.Length; i++) { Console.WriteLine(&quot;s[{0}] = {1}&quot;, i, s[i]); } }
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63. Searching in Strings – Example string str = &quot;C# Programming Course&quot;; int index = str.IndexOf(&quot;C#&quot;); // index = 0 index = str.IndexOf(&quot;Course&quot;); // index = 15 index = str.IndexOf(&quot;COURSE&quot;); // index = -1 // IndexOf is case-sensetive. -1 means not found index = str.IndexOf(&quot;ram&quot;); // index = 7 index = str.IndexOf(&quot;r&quot;); // index = 4 index = str.IndexOf(&quot;r&quot;, 5); // index = 7 index = str.IndexOf(&quot;r&quot;, 8); // index = 18 index = s[index] = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 … C # P r o g r a m m i n g …
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79. Collection Classes Lists, Trees, Dictionaries
  • 80.
  • 81.
  • 82. List<T> – Simple Example static void Main() { List<string> list = new List<string>(); list.Add(&quot;C#&quot;); list.Add(&quot;Java&quot;); list.Add(&quot;PHP&quot;); foreach (string item in list) { Console.WriteLine(item); } // Result: // C# // Java // PHP }
  • 83.
  • 84.
  • 85. Primes in an Interval – Example static List<int> FindPrimes(int start, int end) { List<int> primesList = new List<int>(); for (int num = start; num <= end; num++) { bool prime = true; for (int div = 2; div <= Math.Sqrt(num); div++) { if (num % div == 0) { prime = false; break; } } if (prime) { primesList.Add(num); } } return primesList; }
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93. Dictionary<TKey,Tvalue> – Example Dictionary<string, int> studentsMarks = new Dictionary<string, int>(); studentsMarks.Add(&quot;Ivan&quot;, 4); studentsMarks.Add(&quot;Peter&quot;, 6); studentsMarks.Add(&quot;Maria&quot;, 6); studentsMarks.Add(&quot;George&quot;, 5); int peterMark = studentsMarks[&quot;Peter&quot;]; Console.WriteLine(&quot;Peter's mark: {0}&quot;, peterMark); Console.WriteLine(&quot;Is Peter in the hash table: {0}&quot;, studentsMarks.ContainsKey(&quot;Peter&quot;)); Console.WriteLine(&quot;Students and grades:&quot;); foreach (var pair in studentsMarks) { Console.WriteLine(&quot;{0} --> {1} &quot;, pair.Key, pair.Value); }
  • 94. Counting Words in Given Text string text = &quot;Welcome to our C# course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in C# and Microsoft .NET&quot;; string[] words = text.Split(new char[] {' ', ',', '.'}, StringSplitOptions.RemoveEmptyEntries); var wordsCount = new Dictionary<string, int>(); foreach (string word in words) { if (wordsCount.ContainsKey(word)) wordsCount[word]++; else wordsCount.Add(word, 1); } foreach (var pair in wordsCount) { Console.WriteLine(&quot;{0} --> {1}&quot;, pair.Key, pair.Value); }
  • 95.
  • 96. Sorted Dictionary – Example string text = &quot;Welcome to our C# course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in C# and Microsoft .NET&quot;; string[] words = text.Split(new char[] {' ', ',', '.'}, StringSplitOptions.RemoveEmptyEntries); var wordsCount = new SortedDictionary<string, int>(); foreach (string word in words) { if (wordsCount.ContainsKey(word)) wordsCount[word]++; else wordsCount.Add(word, 1); } foreach (var pair in wordsCount) { Console.WriteLine(&quot;{0} --> {1}&quot;, pair.Key, pair.Value); }
  • 97. Attributes What They Are? How and When to Use Them?
  • 98.
  • 99.
  • 100.
  • 101.

Editor's Notes

  1. * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  2. * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  3. * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  4. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  5. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  6. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  7. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  8. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  9. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  10. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  11. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  12. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  13. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  14. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  15. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  16. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  17. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ## Introducing the StringBuffer Class StringBuffer represents strings that can be modified and extended at run time. The following example creates three new String objects, and copies all the characters each time a new String is created: String quote = &amp;quot;Fasten your seatbelts, &amp;quot;; quote = quote + &amp;quot;it’s going to be a bumpy night.&amp;quot;; It is more efficient to preallocate the amount of space required using the StringBuffer constructor, and its append() method as follows: StringBuffer quote = new StringBuffer(60); // alloc 60 chars quote.append(&amp;quot;Fasten your seatbelts, &amp;quot;); quote.append(&amp;quot; it’s going to be a bumpy night. &amp;quot;); StringBuffer also provides a number of overloaded insert() methods for inserting various types of data at a particular location in the string buffer. Instructor Note The example in the slide uses StringBuffer to reverse the characters in a string. A StringBuffer object is created, with the same length as the string. The loop traverses the String parameter in reverse order and appends each of its characters to the StringBuffer object by using append() . The StringBuffer therefore holds a reverse copy of the String parameter. At the end of the method, a new String object is created from the StringBuffer object, and this String is returned from the method .
  18. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  19. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  20. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  21. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  22. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##