SlideShare a Scribd company logo
1 of 26
What’s New in C# 4.0 Abed El-Azeem Bukhari  (MCPD,MCTS,MCP) el-bukhari.com
private int test; public int Test { get { return test } set { test = value; } } public int MyProperty { get; set; } Short-form Properties What’s new in C# 3.5?
Object and collection Initialize public class MyStructure { public int MyProperty1 { get; set; } public int MyProperty2 { get; set; } } MyStructure myStructure = new MyStructure()  { MyProperty1 = 5, MyProperty2 = 10  }; List < int > myInts = new List < int > () {  5, 10, 15, 20, 25  }; What’s new in C# 3.5?
What’s new in C# 4.0 public void Myfunction( string param1 =“flykit&quot; , bool param2  = false , int param3  = 24  ) { } As VB.NET, You can put default values for the parameters.  Optional Parameters
Named Parameters  Myfunction(“najah&quot;,50); // Error ! Myfunction(“najah&quot;,param3: 50); public void Myfunction( string param1 =“flykit&quot; , bool param2  = false , int param3  = 24  ) { }
COM interop ((Excel.Range)excel.Cells[1, 1]).Value = “Hiiiiiiiii&quot;; excel.Cells[1, 1].Value = &quot;Hiiiiiiiii&quot;;
Variance IList<string> strings = new List<string>(); IList<object> objects = strings;// Error IEnumerable<object> objects = strings;
Dynamic Programming object calculator = GetCalculator();  Type calculatorType = calculator.GetType(); object res = calculatorType.InvokeMember(&quot;Add&quot;, BindingFlags.InvokeMethod, null, calculator, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); And what if the calculator was a JavaScript object? ScriptObject calculator = GetCalculator();  object res = calculator.Invoke(&quot;Add&quot;, 10, 20);  int sum = Convert.ToInt32(res);  For each dynamic domain we have a different programming experience and that makes it very hard to unify the code. With C# 4.0 it becomes possible to write code this way: dynamic calculator = GetCalculator();  int sum = calculator.Add(10, 20);
Dynamic Programming cont. dynamic x = 1;  dynamic y = &quot;Hello&quot;;  dynamic z = new List<int> { 1, 2, 3 }; Code Resolution Method double x = 1.75; double y =  Math .Abs(x); compile-time double Abs(double x) dynamic x = 1.75; dynamic y =  Math .Abs(x); run-time double Abs(double x) dynamic x = 2; dynamic y =  Math .Abs(x);  run-time int Abs(int x)
Diffrence between  var  and  dynamic  keyword: string s = “We are DotNet  Students&quot;; var  test = s;  Console.WriteLine (test.MethodDoesnotExist());//  Error 'string' does not contain a definition for 'MethodDoesnotExist'  and no extension method 'MethodDoesnotExist' string s = “We are DotNet  Students&quot;; dynamic  test = s; Console.WriteLine (test.MethodDoesnotExist());// OK! Used for programming with COM  or JavaScript which can have runtime properties!!
System.Tuple var squaresList = System.Tuple.Create(1, 4, 9, 16, 25, 36, 49, 64);       Console.WriteLine(&quot;1st item: {0}&quot;, squaresList.Item1); //1   Console.WriteLine(&quot;4th item: {0}&quot;, squaresList.Item4); //16   Console.WriteLine(&quot;8th item: {0}&quot;, squaresList.Rest); //(64) Console.ReadKey();     Console.WriteLine(Environment.NewLine);           
System.Tuple cont.   var tupleWithMoreThan8Elements =    System.Tuple.Create(&quot; is&quot;, 2.3, 4.0f,  new List<CHAR> { 'e', 't', 'h' }, “najah dotnet&quot;, new Stack<INT>(4), &quot;best&quot;, squaresList);    // we'll sort the list of chars in descending order    tupleWithMoreThan8Elements.Item4.Sort();    tupleWithMoreThan8Elements.Item4.Reverse();          Console.WriteLine(&quot;{0} {1} {2} {3}&quot;, tupleWithMoreThan8Elements.Item5,  tupleWithMoreThan8Elements.Item1,    string.Concat(tupleWithMoreThan8Elements.Item4),     tupleWithMoreThan8Elements.Item7); //  najah dotnet is the best Console.WriteLine(&quot;Rest: {0}&quot;, tupleWithMoreThan8Elements.Rest);  Console.WriteLine(&quot;Rest's 2nd element: {0}&quot;, tupleWithMoreThan8Elements.Rest.Item1.Item2);  Console.WriteLine(&quot;Rest's 5th element: {0}&quot;, tupleWithMoreThan8Elements.Rest.Item1.Item5);  Console.ReadKey();  Output : Rest: ((1, 4, 9, 16, 25, 36, 49, 64)) Rest's 2nd element: 4 Rest's 5th element: 25     
System.Numerics  Complex numbers static void Main(string[] args) {      var z1 = new Complex(); // this creates complex zero (0, 0)      var z2 = new Complex(2, 4);      var z3 = new Complex(3, 5);        Console.WriteLine(&quot;Complex zero: &quot; + z1);      Console.WriteLine(z2 + &quot; + &quot; + z3 + &quot; = &quot; + (z2 + z3));        Console.WriteLine(&quot;|z2| = &quot; + z2.Magnitude);      Console.WriteLine(&quot;Phase of z2 = &quot; + z2.Phase);        Console.ReadLine(); } Complex zero: (0, 0)  (2, 4) + (3, 5) = (5, 9)  |z2| = 4,47213595499958  Phase of z2 = 1,10714871779409 Output
System.Numerics  Complex numbers cont. static void Main(string[] args) {      var z2 = new Complex(2, 4);      var z3 = new Complex(3, 5);        var z4 = Complex.Add(z2, z3);      var z5 = Complex.Subtract(z2, z3);      var z6 = Complex.Multiply(z2, z3);      var z7 = Complex.Divide(z2, z3);        Console.WriteLine(&quot;z2 + z3 = &quot; + z4);      Console.WriteLine(&quot;z2 - z3 = &quot; + z5);      Console.WriteLine(&quot;z2 * z3 = &quot; + z6);      Console.WriteLine(&quot;z2 / z3 = &quot; + z7);      Console.ReadLine(); } Output z2 + z3 = (5, 9)  z2 - z3 = (-1, -1)  z2 * z3 = (-14, 22) z2 / z3 = (0,76470588235, 0,058823529411)
Parallel Programming
 
 
Parallel Programming For Loop using System.Threading.Tasks ; .. //serial implementation  for (int i = 0; i < 10; i++) { //Do stuff .. anything } //parallel implementation  Parallel.For(0, 10, i => { /*anything with i*/ } );
Parallel Programming  PLINQ bool[] results = new bool[arr.Length]; // arr is array of integers for (int i = 0; i < arr.Length; i++) { results[i] = IsPrime(arr[i]);  } //LINQ to Objects bool[] results1 = arr.Select(x => IsPrime(x)) .ToArray();  //PLINQ bool[] results2 = arr.AsParallel().Select(x => IsPrime(x)) .ToArray();
Parallel Tasks (Debug Menu -> Windows -> Parallel Tasks):
thread-safe-data-structures Queue : ConcurrentQueue<T> ConcurrentQueue<int> queue = new ConcurrentQueue<int>(); queue.Enqueue(10);  int t; Console.WriteLine(queue.TryPeek(out t)); Console.WriteLine(queue.TryDequeue(out t));
thread-safe-data-structures cont. Stack : ConcurrentStack<T> ConcurrentStack<int> stack = new ConcurrentStack<int>(); stack.Push(10); stack.PushRange(new int[] { 1, 2, 3, 4, 5 });  int t; if (stack.TryPop(out t)){  Console.WriteLine(&quot;Pop: &quot; + t);} if (stack.TryPeek(out t)){ Console.WriteLine(&quot;Peek: &quot; + t);} int[] ts = new int[5]; int count; if ((count = stack.TryPopRange(ts, 0, 3)) > 0){ Console.WriteLine(&quot;PopRange&quot;);  for (int i = 0; i < count; i++) { Console.WriteLine(ts[i]); }}
thread-safe-data-structures cont. Collection : ConcurrentBag<T> ConcurrentBag<int> bag = new ConcurrentBag<int>(new int[] { 1, 1, 2, 3 }); bag.Add(70);   int t; bag.TryPeek(out t); Console.WriteLine(t);   bag.Add(110);  Console.WriteLine(); for (int i = 0; i < 3; i++){ bag.TryTake(out t);  Console.WriteLine(t);}
Another Additions ,[object Object],[object Object]
Another Additions cont. ,[object Object],[object Object]
Thanks for Attending Abed El-Azeem Bukhari  (MCPD,MCTS,MCP) el-bukhari.com

More Related Content

What's hot

Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereSergey Platonov
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th StudyChris Ohk
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
Metaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispMetaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispDamien Cassou
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"OdessaJS Conf
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.lnikolaeva
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"OdessaJS Conf
 
Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Anton Bikineev
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programsMukesh Tekwani
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st StudyChris Ohk
 
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014Fantix King 王川
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
C# console programms
C# console programmsC# console programms
C# console programmsYasir Khan
 

What's hot (20)

Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhere
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Metaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common LispMetaprogramming and Reflection in Common Lisp
Metaprogramming and Reflection in Common Lisp
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.TCO in Python via bytecode manipulation.
TCO in Python via bytecode manipulation.
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Writing good std::future&lt;c++>
Writing good std::future&lt;c++>
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
C#
C#C#
C#
 
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
 
Travel management
Travel managementTravel management
Travel management
 
C# console programms
C# console programmsC# console programms
C# console programms
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Python Async IO Horizon
Python Async IO HorizonPython Async IO Horizon
Python Async IO Horizon
 

Similar to Whats new in_csharp4

Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheeltcurdt
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0Yaser Zhian
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsPVS-Studio
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
COMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdfCOMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdffazalenterprises
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012Connor McDonald
 

Similar to Whats new in_csharp4 (20)

Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code Contracts
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Thread
ThreadThread
Thread
 
COMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdfCOMP360 Assembler Write an assembler that reads the source code of an.pdf
COMP360 Assembler Write an assembler that reads the source code of an.pdf
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 

More from Abed Bukhari

Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuplesAbed Bukhari
 
Csharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsCsharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsAbed Bukhari
 
Csharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsCsharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsAbed Bukhari
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_typesAbed Bukhari
 
Csharp4 inheritance
Csharp4 inheritanceCsharp4 inheritance
Csharp4 inheritanceAbed Bukhari
 

More from Abed Bukhari (8)

Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
 
Csharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsCsharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_events
 
Csharp4 generics
Csharp4 genericsCsharp4 generics
Csharp4 generics
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
Csharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsCsharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressions
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
Csharp4 inheritance
Csharp4 inheritanceCsharp4 inheritance
Csharp4 inheritance
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Whats new in_csharp4

  • 1. What’s New in C# 4.0 Abed El-Azeem Bukhari (MCPD,MCTS,MCP) el-bukhari.com
  • 2. private int test; public int Test { get { return test } set { test = value; } } public int MyProperty { get; set; } Short-form Properties What’s new in C# 3.5?
  • 3. Object and collection Initialize public class MyStructure { public int MyProperty1 { get; set; } public int MyProperty2 { get; set; } } MyStructure myStructure = new MyStructure() { MyProperty1 = 5, MyProperty2 = 10 }; List < int > myInts = new List < int > () { 5, 10, 15, 20, 25 }; What’s new in C# 3.5?
  • 4. What’s new in C# 4.0 public void Myfunction( string param1 =“flykit&quot; , bool param2 = false , int param3 = 24 ) { } As VB.NET, You can put default values for the parameters. Optional Parameters
  • 5. Named Parameters Myfunction(“najah&quot;,50); // Error ! Myfunction(“najah&quot;,param3: 50); public void Myfunction( string param1 =“flykit&quot; , bool param2 = false , int param3 = 24 ) { }
  • 6. COM interop ((Excel.Range)excel.Cells[1, 1]).Value = “Hiiiiiiiii&quot;; excel.Cells[1, 1].Value = &quot;Hiiiiiiiii&quot;;
  • 7. Variance IList<string> strings = new List<string>(); IList<object> objects = strings;// Error IEnumerable<object> objects = strings;
  • 8. Dynamic Programming object calculator = GetCalculator(); Type calculatorType = calculator.GetType(); object res = calculatorType.InvokeMember(&quot;Add&quot;, BindingFlags.InvokeMethod, null, calculator, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); And what if the calculator was a JavaScript object? ScriptObject calculator = GetCalculator(); object res = calculator.Invoke(&quot;Add&quot;, 10, 20); int sum = Convert.ToInt32(res); For each dynamic domain we have a different programming experience and that makes it very hard to unify the code. With C# 4.0 it becomes possible to write code this way: dynamic calculator = GetCalculator(); int sum = calculator.Add(10, 20);
  • 9. Dynamic Programming cont. dynamic x = 1; dynamic y = &quot;Hello&quot;; dynamic z = new List<int> { 1, 2, 3 }; Code Resolution Method double x = 1.75; double y = Math .Abs(x); compile-time double Abs(double x) dynamic x = 1.75; dynamic y = Math .Abs(x); run-time double Abs(double x) dynamic x = 2; dynamic y = Math .Abs(x); run-time int Abs(int x)
  • 10. Diffrence between var and dynamic keyword: string s = “We are DotNet Students&quot;; var test = s; Console.WriteLine (test.MethodDoesnotExist());// Error 'string' does not contain a definition for 'MethodDoesnotExist' and no extension method 'MethodDoesnotExist' string s = “We are DotNet Students&quot;; dynamic test = s; Console.WriteLine (test.MethodDoesnotExist());// OK! Used for programming with COM or JavaScript which can have runtime properties!!
  • 11. System.Tuple var squaresList = System.Tuple.Create(1, 4, 9, 16, 25, 36, 49, 64);      Console.WriteLine(&quot;1st item: {0}&quot;, squaresList.Item1); //1   Console.WriteLine(&quot;4th item: {0}&quot;, squaresList.Item4); //16   Console.WriteLine(&quot;8th item: {0}&quot;, squaresList.Rest); //(64) Console.ReadKey();    Console.WriteLine(Environment.NewLine);          
  • 12. System.Tuple cont.   var tupleWithMoreThan8Elements =   System.Tuple.Create(&quot; is&quot;, 2.3, 4.0f, new List<CHAR> { 'e', 't', 'h' }, “najah dotnet&quot;, new Stack<INT>(4), &quot;best&quot;, squaresList);   // we'll sort the list of chars in descending order   tupleWithMoreThan8Elements.Item4.Sort();   tupleWithMoreThan8Elements.Item4.Reverse();         Console.WriteLine(&quot;{0} {1} {2} {3}&quot;, tupleWithMoreThan8Elements.Item5, tupleWithMoreThan8Elements.Item1,   string.Concat(tupleWithMoreThan8Elements.Item4),    tupleWithMoreThan8Elements.Item7); // najah dotnet is the best Console.WriteLine(&quot;Rest: {0}&quot;, tupleWithMoreThan8Elements.Rest); Console.WriteLine(&quot;Rest's 2nd element: {0}&quot;, tupleWithMoreThan8Elements.Rest.Item1.Item2); Console.WriteLine(&quot;Rest's 5th element: {0}&quot;, tupleWithMoreThan8Elements.Rest.Item1.Item5); Console.ReadKey(); Output : Rest: ((1, 4, 9, 16, 25, 36, 49, 64)) Rest's 2nd element: 4 Rest's 5th element: 25     
  • 13. System.Numerics Complex numbers static void Main(string[] args) {     var z1 = new Complex(); // this creates complex zero (0, 0)     var z2 = new Complex(2, 4);     var z3 = new Complex(3, 5);       Console.WriteLine(&quot;Complex zero: &quot; + z1);     Console.WriteLine(z2 + &quot; + &quot; + z3 + &quot; = &quot; + (z2 + z3));       Console.WriteLine(&quot;|z2| = &quot; + z2.Magnitude);     Console.WriteLine(&quot;Phase of z2 = &quot; + z2.Phase);       Console.ReadLine(); } Complex zero: (0, 0) (2, 4) + (3, 5) = (5, 9) |z2| = 4,47213595499958 Phase of z2 = 1,10714871779409 Output
  • 14. System.Numerics Complex numbers cont. static void Main(string[] args) {     var z2 = new Complex(2, 4);     var z3 = new Complex(3, 5);       var z4 = Complex.Add(z2, z3);     var z5 = Complex.Subtract(z2, z3);     var z6 = Complex.Multiply(z2, z3);     var z7 = Complex.Divide(z2, z3);       Console.WriteLine(&quot;z2 + z3 = &quot; + z4);     Console.WriteLine(&quot;z2 - z3 = &quot; + z5);     Console.WriteLine(&quot;z2 * z3 = &quot; + z6);     Console.WriteLine(&quot;z2 / z3 = &quot; + z7);     Console.ReadLine(); } Output z2 + z3 = (5, 9) z2 - z3 = (-1, -1) z2 * z3 = (-14, 22) z2 / z3 = (0,76470588235, 0,058823529411)
  • 16.  
  • 17.  
  • 18. Parallel Programming For Loop using System.Threading.Tasks ; .. //serial implementation for (int i = 0; i < 10; i++) { //Do stuff .. anything } //parallel implementation Parallel.For(0, 10, i => { /*anything with i*/ } );
  • 19. Parallel Programming PLINQ bool[] results = new bool[arr.Length]; // arr is array of integers for (int i = 0; i < arr.Length; i++) { results[i] = IsPrime(arr[i]); } //LINQ to Objects bool[] results1 = arr.Select(x => IsPrime(x)) .ToArray(); //PLINQ bool[] results2 = arr.AsParallel().Select(x => IsPrime(x)) .ToArray();
  • 20. Parallel Tasks (Debug Menu -> Windows -> Parallel Tasks):
  • 21. thread-safe-data-structures Queue : ConcurrentQueue<T> ConcurrentQueue<int> queue = new ConcurrentQueue<int>(); queue.Enqueue(10);  int t; Console.WriteLine(queue.TryPeek(out t)); Console.WriteLine(queue.TryDequeue(out t));
  • 22. thread-safe-data-structures cont. Stack : ConcurrentStack<T> ConcurrentStack<int> stack = new ConcurrentStack<int>(); stack.Push(10); stack.PushRange(new int[] { 1, 2, 3, 4, 5 });  int t; if (stack.TryPop(out t)){ Console.WriteLine(&quot;Pop: &quot; + t);} if (stack.TryPeek(out t)){ Console.WriteLine(&quot;Peek: &quot; + t);} int[] ts = new int[5]; int count; if ((count = stack.TryPopRange(ts, 0, 3)) > 0){ Console.WriteLine(&quot;PopRange&quot;); for (int i = 0; i < count; i++) { Console.WriteLine(ts[i]); }}
  • 23. thread-safe-data-structures cont. Collection : ConcurrentBag<T> ConcurrentBag<int> bag = new ConcurrentBag<int>(new int[] { 1, 1, 2, 3 }); bag.Add(70);   int t; bag.TryPeek(out t); Console.WriteLine(t);   bag.Add(110);  Console.WriteLine(); for (int i = 0; i < 3; i++){ bag.TryTake(out t); Console.WriteLine(t);}
  • 24.
  • 25.
  • 26. Thanks for Attending Abed El-Azeem Bukhari (MCPD,MCTS,MCP) el-bukhari.com