This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Adding elements | |
| var arlist = new ArrayList(); | |
| arlist.Add(1); | |
| arlist.Add("Bill"); | |
| arlist.Add(" "); | |
| arlist.Add(true); | |
| arlist.Add(4.5); | |
| arlist.Add(null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Access individual item using indexer | |
| int firstElement = (int) arlist[0]; | |
| string secondElement = (string) arlist[1]; | |
| //using var keyword without explicit casting | |
| var firstElement = arlist[0]; | |
| var secondElement = arlist[1]; | |
| //update elements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List<int> primeNumbers = new List<int>(); | |
| primeNumbers.Add(1); | |
| primeNumbers.Add(3); | |
| primeNumbers.Add(5); | |
| primeNumbers.Add(7); | |
| var cities = new List<string>(); | |
| cities.Add("NewYork"); | |
| cities.Add("London"); | |
| cities.Add("Mumbai"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Access individual item using indexer | |
| List<int> numbers = new List<int>() | |
| { 1, 2, 5, 7, 8, 10 }; | |
| Console.WriteLine(numbers[0]); // prints 1 | |
| Console.WriteLine(numbers[1]); // prints 2 | |
| Console.WriteLine(numbers[2]); // prints 5 | |
| Console.WriteLine(numbers[3]); // prints 7 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BlockingCollection<int> data = new BlockingCollection<int>(); | |
| Task t1 = Task.Run(() =>{ | |
| data .Add(1); | |
| data .Add(2); | |
| data .Add(3); | |
| data .CompleteAdding(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Task t2 = Task.Run(() => | |
| { | |
| try | |
| { | |
| while (true) | |
| Console.WriteLine(bc.Take()); | |
| } | |
| catch (InvalidOperationException) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IList<string> stringList = new List<string>() | |
| { | |
| "C# Tutorials", | |
| "TS Tutorials", | |
| "Learn python", | |
| "nodejs Tutorials" , | |
| "adonisjs" | |
| }; // LINQ Query Syntax | |
| var result = stringList.Where(s => s.Contains("Tutorials")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Grade{ | |
| public int GradeId { get; set; } | |
| public string GradeName { get; set; } | |
| public ICollection<Student> Students { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Student{ | |
| public int ID { get; set; } | |
| public string Name { get;set;} | |
| public Grade Grade { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SchoolContext: DbContext{ | |
| public SchoolContext():base(){} | |
| public DbSet<Student> Students; | |
| public DbSet<Grade> Grades; | |
| } |
OlderNewer