SlideShare una empresa de Scribd logo
1 de 11
Lesson 11
Learn C#. Series of C# lessons
http://csharp.honcharuk.me/lesson-11
Agenda
• LINQ (Language-Integrated Query)
• Generics
• System.Collections.Generic
• Attributes
• Reflection
• Exporter demo
LINQ (Language-Integrated Query)
• A query is an expression that retrieves data from a data source.
• All LINQ query operations consist of three distinct actions:
1. Obtain the data source
2. Create the query
3. Execute the query
var numbers = new[] {12, 3, 7, 4, 3, 1, 8, 22,
65, 33, 7, 9, 3, 3};
var evenNumbers = numbers.Where(x => x%2 == 0);
foreach (var evenNumber in evenNumbers)
{
Console.WriteLine(evenNumber);
}
var numbers = new[] {12, 3, 7, 4, 3, 1, 8, 22, 65, 33,
7, 9, 3, 3};
var evenNumbers = numbers.Where(x => x%2 == 0)
.Select(x=> $"Number {x} is even.");
foreach (var evenNumber in evenNumbers)
{
Console.WriteLine(evenNumber);
}
Example of Generic class
class Swapper<T>
{
public void Swap(ref T a, ref T b)
{
T temp = a;
a = b;
b = temp;
}
}
Some type that can be passed into the class
Generic class usage
class Program
{
class SuperValue
{
public string Value { get; set; }
}
static void Main(string[] args)
{
int x = 12;
int y = 20;
SuperValue value1 = new SuperValue { Value = "Hello” };
SuperValue value2 = new SuperValue { Value = "World" };
Swapper<int> swapperOne = new Swapper<int>();
var swapperTwo = new Swapper<SuperValue>();
swapperOne.Swap(ref x, ref y);
swapperTwo.Swap(ref value1, ref value2);
Console.WriteLine($"x = {x}, y = {y}");
Console.WriteLine($"v1 = {value1.Value}, v2 = {value2.Value}");
Console.ReadLine();
}
}
Generic Constraints
By default, a type parameter can be substituted with any type whatsoever. Constraints can be
applied to a type parameter to require more specific type arguments:
 where T : base-class // Base-class constraint
 where T : interface // Interface constraint
 where T : class // Reference-type constraint
 where T : struct // Value-type constraint (excludes Nullable types)
 where T : new() // Parameterless constructor constraint
 where U : T // Naked type constraint
class Swapper<T> where T:class
{
public void Swap(ref T a, ref T b)
{
T temp = a;
a = b;
b = temp;
}
}
Swapper<int> swapperOne = new Swapper<int>();
int is not a reference type!!!
System.Collections.Generic
List<string> names = new List<string>();
names.Add("John");
names.Add("Mike");
names.Add("Alan");
foreach (var name in names)
{
Console.WriteLine(name);
}
Dictionary<string,string> bouquet = new Dictionary<string, string>();
bouquet.Add("rose", "red");
bouquet.Add("tulip", "yellow");
bouquet.Add("chamomile", "white");
bouquet.Add("aster", "white");
Console.WriteLine($"Rose's color is {bouquet["rose"]}.");
Console.WriteLine("All flowers in bouquet.");
Console.WriteLine($"Total number is {bouquet.Count}");
foreach (var flower in bouquet)
{
Console.WriteLine($"{flower.Key} is {flower.Value}");
}
Console.WriteLine("White flowers are:");
foreach (var flower in bouquet.Where(x=>x.Value== "white"))
{
Console.WriteLine($"{flower.Key}");
}v
Attributes
• Attributes extend classes and types. This C# feature allows you to
attach declarative information to any type
class DisplayValueAttribute : Attribute
{
public string Text { get; set; }
}
class Record
{
[DisplayValue(Text="Name of the record")]
public string Name { get; set; }
public string Value { get; set; }
[DisplayValue(Text = "Created at")]
public DateTime Created { get; set; }
[Hide]
public DateTime Changed { get; set; }
}
public class HideAttribute : Attribute
{
}
Reflection
• Reflection objects are used for obtaining type information at runtime.
The classes that give access to the metadata of a running program are
in the System.Reflection namespace.
int i = 42;
Type type = i.GetType();
Console.WriteLine(type);
System.Reflection.Assembly info = typeof(int).Assembly;
Console.WriteLine(info);
Exporter demo
Thank you!
Questions?

Más contenido relacionado

La actualidad más candente

Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009David Pollak
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-convertedMicheal Ogundero
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a BossBob Tiernay
 
Introduction to MySQL in PHP
Introduction to MySQL in PHPIntroduction to MySQL in PHP
Introduction to MySQL in PHPhamsa nandhini
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 
Array within a class
Array within a classArray within a class
Array within a classAAKASH KUMAR
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Database design and error handling
Database design and error handlingDatabase design and error handling
Database design and error handlinghamsa nandhini
 
Useful JMeter functions for scripting
Useful JMeter functions for scriptingUseful JMeter functions for scripting
Useful JMeter functions for scriptingTharinda Liyanage
 

La actualidad más candente (20)

Csharp_List
Csharp_ListCsharp_List
Csharp_List
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-converted
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Introduction to MySQL in PHP
Introduction to MySQL in PHPIntroduction to MySQL in PHP
Introduction to MySQL in PHP
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Array within a class
Array within a classArray within a class
Array within a class
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Stacks
StacksStacks
Stacks
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Database design and error handling
Database design and error handlingDatabase design and error handling
Database design and error handling
 
Datastruct2
Datastruct2Datastruct2
Datastruct2
 
Stack queue
Stack queueStack queue
Stack queue
 
Useful JMeter functions for scripting
Useful JMeter functions for scriptingUseful JMeter functions for scripting
Useful JMeter functions for scripting
 
DIG1108 Lesson 6
DIG1108 Lesson 6DIG1108 Lesson 6
DIG1108 Lesson 6
 

Destacado

Portfólio serviços psrv
Portfólio serviços psrvPortfólio serviços psrv
Portfólio serviços psrvRomulo Bokorni
 
La théorie des rôles en équipe de Belbin.
La théorie des rôles en équipe de Belbin.La théorie des rôles en équipe de Belbin.
La théorie des rôles en équipe de Belbin.Daf Ossouala
 
Living in the future
Living in the futureLiving in the future
Living in the futureMar Jurado
 
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...Notis Mitarachi
 
Stress management techniques suggested by custom soft
Stress management techniques  suggested by custom softStress management techniques  suggested by custom soft
Stress management techniques suggested by custom softCustom Soft
 
Cloud Computing for Startups
Cloud Computing for StartupsCloud Computing for Startups
Cloud Computing for StartupsYong Li
 

Destacado (13)

Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Portfólio serviços psrv
Portfólio serviços psrvPortfólio serviços psrv
Portfólio serviços psrv
 
Biotesty
BiotestyBiotesty
Biotesty
 
La théorie des rôles en équipe de Belbin.
La théorie des rôles en équipe de Belbin.La théorie des rôles en équipe de Belbin.
La théorie des rôles en équipe de Belbin.
 
Skrillex
SkrillexSkrillex
Skrillex
 
Alejandro serrato
Alejandro serratoAlejandro serrato
Alejandro serrato
 
Lesson8
Lesson8Lesson8
Lesson8
 
Tool Wear.Rep
Tool Wear.RepTool Wear.Rep
Tool Wear.Rep
 
Living in the future
Living in the futureLiving in the future
Living in the future
 
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...
Απάντηση σε ερώτηση Ν. Μηταράκη σχετικά με την επιτάχυνση της νέας διαδικασία...
 
Stress management techniques suggested by custom soft
Stress management techniques  suggested by custom softStress management techniques  suggested by custom soft
Stress management techniques suggested by custom soft
 
Cloud Computing for Startups
Cloud Computing for StartupsCloud Computing for Startups
Cloud Computing for Startups
 
Puzzles sh pandillas vertical
Puzzles sh pandillas verticalPuzzles sh pandillas vertical
Puzzles sh pandillas vertical
 

Similar a Lesson11

Similar a Lesson11 (20)

Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
C# programming
C# programming C# programming
C# programming
 
Adventures in TclOO
Adventures in TclOOAdventures in TclOO
Adventures in TclOO
 
PostThis
PostThisPostThis
PostThis
 
Linq intro
Linq introLinq intro
Linq intro
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 

Más de Alex Honcharuk (6)

Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Lesson9
Lesson9Lesson9
Lesson9
 
Lesson6
Lesson6Lesson6
Lesson6
 
Lesson5
Lesson5Lesson5
Lesson5
 
Lesson2
Lesson2Lesson2
Lesson2
 
Lesson1
Lesson1Lesson1
Lesson1
 

Último

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 

Último (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 

Lesson11

  • 1. Lesson 11 Learn C#. Series of C# lessons http://csharp.honcharuk.me/lesson-11
  • 2. Agenda • LINQ (Language-Integrated Query) • Generics • System.Collections.Generic • Attributes • Reflection • Exporter demo
  • 3. LINQ (Language-Integrated Query) • A query is an expression that retrieves data from a data source. • All LINQ query operations consist of three distinct actions: 1. Obtain the data source 2. Create the query 3. Execute the query var numbers = new[] {12, 3, 7, 4, 3, 1, 8, 22, 65, 33, 7, 9, 3, 3}; var evenNumbers = numbers.Where(x => x%2 == 0); foreach (var evenNumber in evenNumbers) { Console.WriteLine(evenNumber); } var numbers = new[] {12, 3, 7, 4, 3, 1, 8, 22, 65, 33, 7, 9, 3, 3}; var evenNumbers = numbers.Where(x => x%2 == 0) .Select(x=> $"Number {x} is even."); foreach (var evenNumber in evenNumbers) { Console.WriteLine(evenNumber); }
  • 4. Example of Generic class class Swapper<T> { public void Swap(ref T a, ref T b) { T temp = a; a = b; b = temp; } } Some type that can be passed into the class
  • 5. Generic class usage class Program { class SuperValue { public string Value { get; set; } } static void Main(string[] args) { int x = 12; int y = 20; SuperValue value1 = new SuperValue { Value = "Hello” }; SuperValue value2 = new SuperValue { Value = "World" }; Swapper<int> swapperOne = new Swapper<int>(); var swapperTwo = new Swapper<SuperValue>(); swapperOne.Swap(ref x, ref y); swapperTwo.Swap(ref value1, ref value2); Console.WriteLine($"x = {x}, y = {y}"); Console.WriteLine($"v1 = {value1.Value}, v2 = {value2.Value}"); Console.ReadLine(); } }
  • 6. Generic Constraints By default, a type parameter can be substituted with any type whatsoever. Constraints can be applied to a type parameter to require more specific type arguments:  where T : base-class // Base-class constraint  where T : interface // Interface constraint  where T : class // Reference-type constraint  where T : struct // Value-type constraint (excludes Nullable types)  where T : new() // Parameterless constructor constraint  where U : T // Naked type constraint class Swapper<T> where T:class { public void Swap(ref T a, ref T b) { T temp = a; a = b; b = temp; } } Swapper<int> swapperOne = new Swapper<int>(); int is not a reference type!!!
  • 7. System.Collections.Generic List<string> names = new List<string>(); names.Add("John"); names.Add("Mike"); names.Add("Alan"); foreach (var name in names) { Console.WriteLine(name); } Dictionary<string,string> bouquet = new Dictionary<string, string>(); bouquet.Add("rose", "red"); bouquet.Add("tulip", "yellow"); bouquet.Add("chamomile", "white"); bouquet.Add("aster", "white"); Console.WriteLine($"Rose's color is {bouquet["rose"]}."); Console.WriteLine("All flowers in bouquet."); Console.WriteLine($"Total number is {bouquet.Count}"); foreach (var flower in bouquet) { Console.WriteLine($"{flower.Key} is {flower.Value}"); } Console.WriteLine("White flowers are:"); foreach (var flower in bouquet.Where(x=>x.Value== "white")) { Console.WriteLine($"{flower.Key}"); }v
  • 8. Attributes • Attributes extend classes and types. This C# feature allows you to attach declarative information to any type class DisplayValueAttribute : Attribute { public string Text { get; set; } } class Record { [DisplayValue(Text="Name of the record")] public string Name { get; set; } public string Value { get; set; } [DisplayValue(Text = "Created at")] public DateTime Created { get; set; } [Hide] public DateTime Changed { get; set; } } public class HideAttribute : Attribute { }
  • 9. Reflection • Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in the System.Reflection namespace. int i = 42; Type type = i.GetType(); Console.WriteLine(type); System.Reflection.Assembly info = typeof(int).Assembly; Console.WriteLine(info);

Notas del editor

  1. https://msdn.microsoft.com/en-us/library/system.collections.generic(v=vs.110).aspx 101 - https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
  2. https://msdn.microsoft.com/en-us/library/system.collections.generic(v=vs.110).aspx
  3. https://msdn.microsoft.com/en-us/library/mt656691.aspx http://www.tutorialspoint.com/csharp/csharp_reflection.htm