SlideShare a Scribd company logo
1 of 17
Download to read offline
Advanced C#
Initializer
StudentName student2 = new StudentName
{
FirstName = “Foulen",
LastName = “Benfoulen",
};
List<string> lst = new List<string>()
{“etd1“, “etd2“, “etd3“, “etd4“ };
Anonymous Types
var variableTypeAnonyme = new { FirstName = "Flavien", Age = 23};
var variableTypeAnonyme = new { DateOfBirth = new DateTime(1984, 11, 15) };
var variableTypeAnonyme = 12;
var variableTypeAnonyme = "Flavien";
Extension methods
public static class Encodage
{
public static string Crypte(string chaine)
{
return
Convert.ToBase64String(Encoding.Default.GetBytes(chaine));
}
public static string Decrypte(string chaine)
{
return
Encoding.Default.GetString(Convert.FromBase64String(chaine));
}
}
Extension methods
static void Main(string[] args)
{
string chaineNormale = "Bonjour";
string chaineCryptee = Encodage.Crypte(chaineNormale)
Console.WriteLine(chaineCryptee);
chaineNormale = Encodage.Decrypte(chaineCryptee);
Console.WriteLine(chaineNormale);
}
Extension methods 2
public static class Encodage
{
public static string Crypte ( this string chaine)
{
return
Convert.ToBase64String(Encoding.Default.GetBytes(chaine));
}
public static string Decrypte ( this string chaine)
{
return
Encoding.Default.GetString(Convert.FromBase64String(chaine));
}
}
Extension methods 2
Delegate
public class TrieurDeTableau
{
private delegate void DelegateTri(int[] tableau);
private void TriAscendant (int[] tableau)
{
Array.Sort(tableau);
}
private void TriDescendant (int[] tableau)
{
Array.Sort(tableau);
Array.Reverse(tableau);
}
}
public class TrieurDeTableau
{
[…Code supprimé pour plus de clarté…]
public void DemoTri(int[] tableau)
{
DelegateTri tri = TriAscendant;
tri(tableau);
//affichage
tri = TriDescendant;
tri(tableau);
//affichage
}}
Using delegates
static void Main(string[] args)
{
int[] tableau = new int[] { 4, 1,10, 8, 5 };
new TrieurDeTableau().DemoTri(tableau);
}
Lambda Expression
Delegate to lambda
DelegateTri tri = delegate(int[] leTableau)
{
Array.Sort(leTableau);
};
DelegateTri tri = (leTableau) =>
{
Array.Sort(leTableau);
};
Lambda
List<int> list = new List<int>(new int[] { 2, -5, 45, 5 });
var positiveNumbers = list.FindAll((int i) => i > 0);
LINQ
From source
Where condition
Select variable
LINQ
class IntroToLINQ{
static void Main()
{
// The Three Parts of a LINQ Query:
// 1. Data source.
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
// 2. Query creation.
// numQuery is an IEnumerable<int>
var numQuery =
from num in numbers
where (num % 2) == 0
select num;
// 3. Query execution.
foreach (int num in numQuery)
{
Console.Write("{0,1} ", num);
}}}
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
var evenNumQuery =
from num in numbers
where (num % 2) == 0
select num;
int evenNumCount = evenNumQuery.Count();
List<int> numQuery2 =
(from num in numbers
where (num % 2) == 0
select num).ToList();
// or like this:
// numQuery3 is still an int[]
var numQuery3 =
(from num in numbers
where (num % 2) == 0
select num).ToArray();

More Related Content

What's hot

First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)
Wildan Maulana
 

What's hot (20)

Java Week4(C) Notepad
Java Week4(C)   NotepadJava Week4(C)   Notepad
Java Week4(C) Notepad
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Understanding static analysis php amsterdam 2018
Understanding static analysis   php amsterdam 2018Understanding static analysis   php amsterdam 2018
Understanding static analysis php amsterdam 2018
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)
 
The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
srgoc
srgocsrgoc
srgoc
 
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev FedorProgramming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
java sockets
 java sockets java sockets
java sockets
 
Day2
Day2Day2
Day2
 
Day3
Day3Day3
Day3
 
Python course Day 1
Python course Day 1Python course Day 1
Python course Day 1
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Java Basics
Java BasicsJava Basics
Java Basics
 
F# Eye for the C# guy - Øredev 2013
F# Eye for the C# guy - Øredev 2013F# Eye for the C# guy - Øredev 2013
F# Eye for the C# guy - Øredev 2013
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212
 

Viewers also liked

C#으로 게임 엔진 만들기(2)
C#으로 게임 엔진 만들기(2)C#으로 게임 엔진 만들기(2)
C#으로 게임 엔진 만들기(2)
지환 김
 
C#으로 게임 엔진 만들기(1)
C#으로 게임 엔진 만들기(1)C#으로 게임 엔진 만들기(1)
C#으로 게임 엔진 만들기(1)
지환 김
 

Viewers also liked (20)

New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
Configuring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky serversConfiguring SSL on NGNINX and less tricky servers
Configuring SSL on NGNINX and less tricky servers
 
NuGet Must Haves for LINQ
NuGet Must Haves for LINQNuGet Must Haves for LINQ
NuGet Must Haves for LINQ
 
Donetconf2016: The Future of C#
Donetconf2016: The Future of C#Donetconf2016: The Future of C#
Donetconf2016: The Future of C#
 
Dynamic C#
Dynamic C# Dynamic C#
Dynamic C#
 
Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developer
 
C# and the Evolution of a Programming Language
C# and the Evolution of a Programming LanguageC# and the Evolution of a Programming Language
C# and the Evolution of a Programming Language
 
C# 6.0 - DotNetNotts
C# 6.0 - DotNetNottsC# 6.0 - DotNetNotts
C# 6.0 - DotNetNotts
 
C# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesC# 7.0 Hacks and Features
C# 7.0 Hacks and Features
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
 
C# 7
C# 7C# 7
C# 7
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
코드의 품질 (Code Quality)
코드의 품질 (Code Quality)코드의 품질 (Code Quality)
코드의 품질 (Code Quality)
 
게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
C#으로 게임 엔진 만들기(2)
C#으로 게임 엔진 만들기(2)C#으로 게임 엔진 만들기(2)
C#으로 게임 엔진 만들기(2)
 
C#으로 게임 엔진 만들기(1)
C#으로 게임 엔진 만들기(1)C#으로 게임 엔진 만들기(1)
C#으로 게임 엔진 만들기(1)
 

Similar to C# features through examples

Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
Paulo Morgado
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
ShashikantSathe3
 

Similar to C# features through examples (20)

Generics and Lambda survival guide - DevNexus 2017
Generics and Lambda survival guide - DevNexus 2017Generics and Lambda survival guide - DevNexus 2017
Generics and Lambda survival guide - DevNexus 2017
 
Java programs
Java programsJava programs
Java programs
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>
 
Java Generics
Java GenericsJava Generics
Java Generics
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Chap1 array
Chap1 arrayChap1 array
Chap1 array
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Java generics
Java genericsJava generics
Java generics
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Linq
LinqLinq
Linq
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 

More from Zayen Chagra

Windows Phone Workshop: WCF services
Windows Phone Workshop: WCF services Windows Phone Workshop: WCF services
Windows Phone Workshop: WCF services
Zayen Chagra
 
Windows Phone Workshop: RSS - WCF - JSON - Media Element
Windows Phone Workshop: RSS - WCF - JSON - Media ElementWindows Phone Workshop: RSS - WCF - JSON - Media Element
Windows Phone Workshop: RSS - WCF - JSON - Media Element
Zayen Chagra
 
Windows Phone Workshop: Globalization
Windows Phone Workshop: GlobalizationWindows Phone Workshop: Globalization
Windows Phone Workshop: Globalization
Zayen Chagra
 
Windows Phone Workshop: Isolated Storage / LINQ to SQL
Windows Phone Workshop: Isolated Storage / LINQ to SQLWindows Phone Workshop: Isolated Storage / LINQ to SQL
Windows Phone Workshop: Isolated Storage / LINQ to SQL
Zayen Chagra
 
Windows Phone Workshop: Navigation and parameters
Windows Phone Workshop: Navigation and parameters Windows Phone Workshop: Navigation and parameters
Windows Phone Workshop: Navigation and parameters
Zayen Chagra
 
Windows Phone Workshop sensors and battery
Windows Phone Workshop sensors and batteryWindows Phone Workshop sensors and battery
Windows Phone Workshop sensors and battery
Zayen Chagra
 
Windows Phone Workshop launchers and choosers
Windows Phone Workshop launchers and choosersWindows Phone Workshop launchers and choosers
Windows Phone Workshop launchers and choosers
Zayen Chagra
 

More from Zayen Chagra (18)

Xamarin introduction
Xamarin introductionXamarin introduction
Xamarin introduction
 
5 one minute Xamarin : MVVM
5 one minute Xamarin : MVVM5 one minute Xamarin : MVVM
5 one minute Xamarin : MVVM
 
3 one minute Xamarin : Custom ListView
3 one minute Xamarin : Custom ListView 3 one minute Xamarin : Custom ListView
3 one minute Xamarin : Custom ListView
 
2 one minute Xamarin: Simple ListView
2 one minute Xamarin: Simple ListView2 one minute Xamarin: Simple ListView
2 one minute Xamarin: Simple ListView
 
1 one minute xamarin : UI
1 one minute xamarin : UI1 one minute xamarin : UI
1 one minute xamarin : UI
 
The very first steps to make my first Mobile App with Xamarin
The very first steps to make my first Mobile App with XamarinThe very first steps to make my first Mobile App with Xamarin
The very first steps to make my first Mobile App with Xamarin
 
Design and User Experience for Windows & Windows Phone
Design and User Experience for Windows & Windows PhoneDesign and User Experience for Windows & Windows Phone
Design and User Experience for Windows & Windows Phone
 
Xamarin first mobile application
Xamarin first mobile applicationXamarin first mobile application
Xamarin first mobile application
 
Intel RealSense technology : Overview and demos
Intel RealSense technology : Overview and demosIntel RealSense technology : Overview and demos
Intel RealSense technology : Overview and demos
 
Dev fest Tunisia 2014: NAO robot and Google technologies
Dev fest Tunisia 2014: NAO robot and Google technologies Dev fest Tunisia 2014: NAO robot and Google technologies
Dev fest Tunisia 2014: NAO robot and Google technologies
 
Windows Phone Workshop: WCF services
Windows Phone Workshop: WCF services Windows Phone Workshop: WCF services
Windows Phone Workshop: WCF services
 
Windows Phone Workshop: RSS - WCF - JSON - Media Element
Windows Phone Workshop: RSS - WCF - JSON - Media ElementWindows Phone Workshop: RSS - WCF - JSON - Media Element
Windows Phone Workshop: RSS - WCF - JSON - Media Element
 
Windows Phone Workshop: Globalization
Windows Phone Workshop: GlobalizationWindows Phone Workshop: Globalization
Windows Phone Workshop: Globalization
 
Windows Phone Workshop: Isolated Storage / LINQ to SQL
Windows Phone Workshop: Isolated Storage / LINQ to SQLWindows Phone Workshop: Isolated Storage / LINQ to SQL
Windows Phone Workshop: Isolated Storage / LINQ to SQL
 
Windows Phone Workshop: Navigation and parameters
Windows Phone Workshop: Navigation and parameters Windows Phone Workshop: Navigation and parameters
Windows Phone Workshop: Navigation and parameters
 
Windows Phone Workshop sensors and battery
Windows Phone Workshop sensors and batteryWindows Phone Workshop sensors and battery
Windows Phone Workshop sensors and battery
 
Windows Phone Workshop launchers and choosers
Windows Phone Workshop launchers and choosersWindows Phone Workshop launchers and choosers
Windows Phone Workshop launchers and choosers
 
Windows 8 seminar presentation
Windows 8 seminar presentationWindows 8 seminar presentation
Windows 8 seminar presentation
 

Recently uploaded

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 

C# features through examples

  • 2. Initializer StudentName student2 = new StudentName { FirstName = “Foulen", LastName = “Benfoulen", }; List<string> lst = new List<string>() {“etd1“, “etd2“, “etd3“, “etd4“ };
  • 3. Anonymous Types var variableTypeAnonyme = new { FirstName = "Flavien", Age = 23}; var variableTypeAnonyme = new { DateOfBirth = new DateTime(1984, 11, 15) }; var variableTypeAnonyme = 12; var variableTypeAnonyme = "Flavien";
  • 4. Extension methods public static class Encodage { public static string Crypte(string chaine) { return Convert.ToBase64String(Encoding.Default.GetBytes(chaine)); } public static string Decrypte(string chaine) { return Encoding.Default.GetString(Convert.FromBase64String(chaine)); } }
  • 5. Extension methods static void Main(string[] args) { string chaineNormale = "Bonjour"; string chaineCryptee = Encodage.Crypte(chaineNormale) Console.WriteLine(chaineCryptee); chaineNormale = Encodage.Decrypte(chaineCryptee); Console.WriteLine(chaineNormale); }
  • 6. Extension methods 2 public static class Encodage { public static string Crypte ( this string chaine) { return Convert.ToBase64String(Encoding.Default.GetBytes(chaine)); } public static string Decrypte ( this string chaine) { return Encoding.Default.GetString(Convert.FromBase64String(chaine)); } }
  • 9. public class TrieurDeTableau { private delegate void DelegateTri(int[] tableau); private void TriAscendant (int[] tableau) { Array.Sort(tableau); } private void TriDescendant (int[] tableau) { Array.Sort(tableau); Array.Reverse(tableau); } }
  • 10. public class TrieurDeTableau { […Code supprimé pour plus de clarté…] public void DemoTri(int[] tableau) { DelegateTri tri = TriAscendant; tri(tableau); //affichage tri = TriDescendant; tri(tableau); //affichage }}
  • 11. Using delegates static void Main(string[] args) { int[] tableau = new int[] { 4, 1,10, 8, 5 }; new TrieurDeTableau().DemoTri(tableau); }
  • 13. Delegate to lambda DelegateTri tri = delegate(int[] leTableau) { Array.Sort(leTableau); }; DelegateTri tri = (leTableau) => { Array.Sort(leTableau); };
  • 14. Lambda List<int> list = new List<int>(new int[] { 2, -5, 45, 5 }); var positiveNumbers = list.FindAll((int i) => i > 0); LINQ From source Where condition Select variable
  • 15. LINQ class IntroToLINQ{ static void Main() { // The Three Parts of a LINQ Query: // 1. Data source. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. // numQuery is an IEnumerable<int> var numQuery = from num in numbers where (num % 2) == 0 select num; // 3. Query execution. foreach (int num in numQuery) { Console.Write("{0,1} ", num); }}}
  • 16. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; var evenNumQuery = from num in numbers where (num % 2) == 0 select num; int evenNumCount = evenNumQuery.Count();
  • 17. List<int> numQuery2 = (from num in numbers where (num % 2) == 0 select num).ToList(); // or like this: // numQuery3 is still an int[] var numQuery3 = (from num in numbers where (num % 2) == 0 select num).ToArray();