This file contains 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 Program | |
{ | |
public static void Main() | |
{ | |
List<string> personList = new List<string> { "Alice", "Bob", "Charlie", "David", "Eve" }; | |
// Accessing the last element | |
string lastPerson = personList[^1]; | |
Console.WriteLine($"Last person: {lastPerson}"); // Output: Eve |
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace BenchmarkExample | |
{ | |
public class Program | |
{ |
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
public class LinqQueryPerformanceBenchmark | |
{ | |
private List<Person> _peopleList; | |
public LinqQueryPerformanceBenchmark() | |
{ | |
_peopleList = new List<Person>(); |
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using System.Collections.Generic; | |
using System.Linq; | |
using BenchmarkDotNet.Order; | |
// Represents a person with an ID and a Name | |
public class Person | |
{ | |
public int Id { get; set; } |
This file contains 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
using MediatR; | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.EntityFrameworkCore; | |
public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | |
{ | |
private readonly DbContext _dbContext; |
This file contains 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
namespace NewInEfCore9; | |
public static class QueryExamples | |
{ | |
public static Task RunUserQuerySample() | |
{ | |
return ExecuteUserQueryTest<UserManagementDbContext>(); | |
} | |
private static async Task ExecuteUserQueryTest<TContext>() |
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Running; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.ObjectPool; | |
using System; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Threading.Tasks; |
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace ClassBenchmark | |
{ | |
public class StandardClass | |
{ | |
public int StandardProperty { get; set; } | |
public int GetStandardProperty() => StandardProperty; |
This file contains 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 interface INumber | |
{ | |
object NumericValue { get; set; } | |
} | |
public class Number : INumber | |
{ | |
public object NumericValue { get; set; } | |
} |
This file contains 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
var intHolder = new Number<int?>(null); // T is int?, which can be null | |
var stringHolder = new Number<string>("Hello"); // T is string | |
var objectHolder = new Number<object>(new object()); // T is object | |
var nullableHolder = new Number<int?>(5); // T is int?, with a value | |
Console.WriteLine(intHolder.Value); // Output: null | |
Console.WriteLine(stringHolder.Value); // Output: Hello | |
Console.WriteLine(objectHolder.Value); // Output: System.Object | |
Console.WriteLine(nullableHolder.Value); // Output: 5 |
NewerOlder