Tutorial by Examples: ed

ConnectionMultiplexer conn = /* initialization */; var profiler = new ToyProfiler(); conn.RegisterProfiler(profiler); var threads = new List<Thread>(); var perThreadTimings = new ConcurrentDictionary<Thread, List<IProfiledCommand>>(); for (var i = 0; i < 16; i++) {...
Simple usage Dapper fully supports stored procs: var user = conn.Query<User>("spGetUser", new { Id = 1 }, commandType: CommandType.StoredProcedure) .SingleOrDefault(); Input, Output and Return parameters If you want something more fancy...
Dapper makes it easy to follow best practice by way of fully parameterized SQL. Parameters are important, so dapper makes it easy to get it right. You just express your parameters in the normal way for your RDBMS (usually @foo, ?foo or :foo) and give dapper an object that has a member called foo...
Verbatim strings can be combined with the new String interpolation features found in C#6. Console.WriteLine($@"Testing \n 1 2 {5 - 2} New line"); Output: Testing \n 1 2 3 New line Live Demo on .NET Fiddle As expected from a verbatim string, the backslashes are ignored as escap...
Expression-bodied function members allow the use of lambda expressions as member bodies. For simple members, it can result in cleaner and more readable code. Expression-bodied functions can be used for properties, indexers, methods, and operators. Properties public decimal TotalPrice => Base...
The fixed statement fixes memory in one location. Objects in memory are usually moving arround, this makes garbage collection possible. But when we use unsafe pointers to memory addresses, that memory must not be moved. We use the fixed statement to ensure that the garbage collector does not relo...
When an object graph is finalized, the order is the reverse of the construction. E.g. the super-type is finalized before the base-type as the following code demonstrates: class TheBaseClass { ~TheBaseClass() { Console.WriteLine("Base class finalized!"); } } ...
// assigning a signed short to its minimum value short s = -32768; // assigning a signed short to its maximum value short s = 32767; // assigning a signed int to its minimum value int i = -2147483648; // assigning a signed int to its maximum value int i = 2147483647; // assigning a s...
// assigning an unsigned short to its minimum value ushort s = 0; // assigning an unsigned short to its maximum value ushort s = 65535; // assigning an unsigned int to its minimum value uint i = 0; // assigning an unsigned int to its maximum value uint i = 4294967295; // assigning an...
public class SomeClass { public void DoStuff() { } protected void DoMagic() { } } public static class SomeClassExtensions { public static void DoStuffWrapper(this SomeClass someInstance) { someInstance.DoStuff(); // ok ...
The checked and unchecked keywords define how operations handle mathematical overflow. "Overflow" in the context of the checked and unchecked keywords is when an integer arithmetic operation results in a value which is greater in magnitude than the target data type can represent. When ove...
public class Model { public string Name { get; set; } public bool? Selected { get; set; } } Here we have a Class with no constructor with two properties: Name and a nullable boolean property Selected. If we wanted to initialize a List<Model>, there are a few different ways to ex...
Visual Studio helps manage user and application settings. Using this approach has these benefits over using the appSettings section of the configuration file. Settings can be made strongly typed. Any type which can be serialized can be used for a settings value. Application settings can be...
Starting from a new Settings class and custom configuration section: Add an application setting named ExampleTimeout, using the time System.Timespan, and set the value to 1 minute: Save the Project Properties, which saves the Settings tab entries, as well as re-generates the custom Settings cl...
When we talk about the GC and the "heap", we're really talking about what's called the managed heap. Objects on the managed heap can access resources not on the managed heap, for example, when writing to or reading from a file. Unexpected behavior can occur when, a file is opened for readi...
SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine(); GrammarBuilder builder = new GrammarBuilder(); builder.Append(new Choices("I am", "You are", "He is", "She is", "We are", "They are")); builder.Append(new Choices...
String.Trim() string x = " Hello World! "; string y = x.Trim(); // "Hello World!" string q = "{(Hi!*"; string r = q.Trim( '(', '*', '{' ); // "Hi!" String.TrimStart() and String.TrimEnd() string q = "{(Hi*"; string r = q.TrimStart( '{...
The following is a bad idea because it would dispose the db variable before returning it. public IDBContext GetDBContext() { using (var db = new DBContext()) { return db; } } This can also create more subtle mistakes: public IEnumerable<Person> GetPeople(int age)...
The following program: class Program { static void Method(params Object[] objects) { System.Console.WriteLine(objects.Length); } static void Method(Object a, Object b) { System.Console.WriteLine("two"); } static void Main(string[] a...
The following examples will not compile: string s = "\c"; char c = '\c'; Instead, they will produce the error Unrecognized escape sequence at compile time.

Page 1 of 145