fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,30 @@
---
title: All
---
# All
Returns true if all the elements in the collection matches the predicate.
### Signature
```csharp
public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// All Fruit have a quantity greater than 0.
var allFruitsHaveAQuantity = fruits.All(f => f.Quantity > 0); // true
// All Fruit have the Color Yellow
var allYellow = fruits.All(f => f.Color == "Yellow"); // false
```

View File

@ -0,0 +1,37 @@
---
title: Any
---
# Any
Returns true if there is at least one element that matches the predicate.
When using an empty predicate (just .Any() without anything between the parantheses) it will return true if the collection is not empty.
### Signature
```csharp
public static bool Any<TSource>(this IEnumerable<TSource> source);
public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate);
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Check if any Fruits have a quantity greater than 20
var anyFruitGreaterThanTwenty = fruits.Any(f => f.Quantity > 20); // true
// Any Fruit with color Green
var anyGreen = fruits.Any(f => f.Color == "Green"); // false
var hasFruits = fruits.Any(); // true
var hasYellowFruit = fruits.Any(f => f.Color == "Yellow"); // true
```

View File

@ -0,0 +1,24 @@
---
title: Count
---
# Any
Returns a count of elements in the sequence that satisfy a condition.
### Signature
```csharp
Enumerable.Count<TSource> Method (IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Count of Fruit with Color Red.
var yellowCount = fruits.Count(f => f.Color == "Red"); // 2
// Count of Fruit with Quantity > 2
var quantityOverTwo = fruits.Count(f => f.Quantity > 2); // 4
```

View File

@ -0,0 +1,28 @@
---
title: First Or Default
---
# FirstOrDefault
Returns the first element that satisfies an optional given condition. If no element is found, the ```default()``` of the object is returned
### Signature
```csharp
Enumerable.FirstOrDefault<TSource>(IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
var firstFruit = fruits.FirstOrDefault(); // Orange
var firstYellowFruit = fruits.FirstOrDefault(f => f.Color == "Green"); // null
```

View File

@ -0,0 +1,29 @@
---
title: First
---
# First
Returns the first element that satisfies an optional given condition. If no element is found, throws an ```InvalidOperationException```;
### Signature
```csharp
Enumerable.First<TSource>(IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
var firstFruit = fruits.First(); // Orange
var firstYellowFruit = fruits.First(f => f.Color == "Yellow"); // Pineapple
```

View File

@ -0,0 +1,62 @@
---
title: LINQ
---
# LINQ (Language Integrated Query)
LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. LINQ offers a compact, expressive, and intelligible syntax for manipulating data. The real value of LINQ comes from its ability to apply the same query to an SQL database, a DataSet, a list, a dictionary, etc.
## Example
LINQ can be used to filter, transform, search data and a lot more of complex tasks. Let's say we have the following list of objects:
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
}
```
Then we can do things like:
```csharp
// Get the name of the first fruit
var firstName = fruits.Select(f => f.Name).First(); // Orange
// Count how many fruits are red
var qntRed = fruits.Where(Color == "Red").Count(); // 2
// Create a list of yellow fruits
var yellowFruits = fruits.Where(f => f.Color == "Yellow").ToList(); // { Pineapple, Mango }
// Orders list by quantity from most to less
var orderedFruits = fruits.OrderByDescending(f => f.Quantity).ToList(); // {Grape, Strawberry, Orange, Apple, Mango, Pineapple}
// Sum the quantity of fruits
var quantity = fruits.Sum(f => f.Quantity); // 53
// Check if there are any green fruits
var hasGreen = fruits.Any(f => f.Color == "Green"); // false
// Group fruits by color into a dictionary
var fruitsByColor = fruits.GroupBy(g => g.Color).ToDictionary(k => k.Key, v => v.ToList()); // Dictionary of list of fruits by color
// linq operations can be concatenated and are not performed as long as data is needed
var logs = new List<Log>;
if (filterBySeverity)
logs = logs.Where(p => p.Severity == severity);
//IQueryable
if (filterByUser)
logs = logs.Where(p => p.User == user);
//IQueryable
result = logs.ToList();
//List<log>
```

View File

@ -0,0 +1,24 @@
---
title: LastOrDefault
---
# Any
Returns the last element in a sequence that satisfies a condition or a default value if no element is found
### Signature
```csharp
Enumerable.LastOrDefault<TSource> Method (IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Returns the last fruit where the Color is Yellow
var lastYellow = fruits.LastOrDefault(f => f.Color == "Yellow"); // Mango
// Returns the last fruit where the quantity is 20
var lastQuantityOfTwenty = fruits.LastOrDefault(f => f.Quantity == 20); // null
```

View File

@ -0,0 +1,28 @@
---
title: Select
---
# Select
Projects data from the data set.
### Signature
```csharp
Enumerable.Select<TSource,TResult> Method (IEnumerable<TSource>,Func<TSource,TResult>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity = 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity = 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity = 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity = 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity = 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity = 2 }
};
var mangoQnt = fruits.Where(f => f.Name == "Mango").Select(f => f.Quantity).FirstOrDefault(); // 2
var grapeColor = fruits.Where(f => f.Name == "Grape").Select(f => f.Color).FirstOrDefault(); // Purple
```

View File

@ -0,0 +1,28 @@
---
title: Single Or Default
---
# SingleOrDefault
Returns the single element in a sequence that satisfies the specified condition or the default value if no element is found. The method will throw an exception if more than one element is found that satisfies the specified condition.
### Signature
```csharp
Enumerable.SingleOrDefault<TSource>(IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
var purpleFruit = fruits.SingleOrDefault(f => f.Color == "Purple"); // Grape
var greenFruit = fruits.SingleOrDefault(f => f.Color == "Green"); // null
```

View File

@ -0,0 +1,33 @@
---
title: To Dictionary
---
# ToDictionary
Greates a Dictionary from the DataSet;
### Signature
```csharp
Enumerable.ToDictionary<TSource,TKey> Method (IEnumerable<TSource>,Func<TSource,TKey>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Generates a Dictionary of Fruits by Id
var fruitsById = fruits.ToDictionary(k => k.Id, v => v); // Dictionary<int, Fruit>
// Generates a dictionary fruits by color
var fruitsByColor = fruits.GroupBy(g => g.Color).ToDictionary(k => k.Key, v => v.ToList()); // Dictionary of list of fruits by color
// Generates a dictionary of quantity of fruits by color
var fruitsByColor = fruits.GroupBy(g => g.Color).ToDictionary(k => k.Key, v => v.Sum(s => s.Quantity)); // Dictionary of sum of fruits by color
```

View File

@ -0,0 +1,27 @@
---
title: To List
---
# ToList
Generates a List given the DataSet queries.
### Signature
```csharp
Enumerable.ToList<TSource> Method (IEnumerable<TSource>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Generates list of fruits name
var fruitsNames = fruits.Select(f => f.Name).ToList(); // { "Orange", "Strawberry", "Grape", "Pineapple", "Apple", "Mango" }
```

View File

@ -0,0 +1,30 @@
---
title: Where
---
# Where
Filters elements from the dataset.
### Signature
```csharp
Enumerable.Where<TSource> Method (IEnumerable<TSource>,Func<TSource,Boolean>)
```
## Example
```csharp
var fruits = new List<Fruit>() {
new Fruit() { Id = 1, Name = "Orange", Color = "Orange", Quantity: 3 },
new Fruit() { Id = 2, Name = "Strawberry", Color = "Red", Quantity: 12 },
new Fruit() { Id = 3, Name = "Grape", Color = "Purple", Quantity: 25 },
new Fruit() { Id = 4, Name = "Pineapple", Color = "Yellow", Quantity: 1 },
new Fruit() { Id = 5, Name = "Apple", Color = "Red", Quantity: 5 },
new Fruit() { Id = 6, Name = "Mango", Color = "Yellow", Quantity: 2 }
};
// Fruits with more than 3 items
var moreThanThree = fruits.Where(f => f.Quantity > 3).ToList(); // { Strawberry, Grape, Apple }
// Fruits that are not red
var notRed = fruits.Where(f => f.Color != "Red").ToList(); // { Orange, Grape, Pineapple, Mango }
```