background preloader

C# & MVC

Facebook Twitter

Default Values Table (C# Reference) Getting Started with ASP.NET MVC 5. This tutorial will teach you the basics of building an ASP.NET MVC 5 web app using Visual Studio 2013.

Getting Started with ASP.NET MVC 5

Download the completed project. This tutorial was written by Scott Guthrie (twitter@scottgu ), Scott Hanselman (twitter: @shanselman ), and Rick Anderson ( @RickAndMSFT ) How to use the IComparable and IComparer interfaces in Visual C# This step-by-step article describes the use of two interfaces: IComparer and IComparable.

How to use the IComparable and IComparer interfaces in Visual C#

These interfaces are discussed in the same article for two reasons. These interfaces are frequently used together, and although the interfaces are similar (and have similar names), they serve different purposes. If you have an array of types (such as string or integer) that already support IComparer, you can sort that array without providing any explicit reference to IComparer. In that case, the elements of the array are cast to the default implementation of IComparer (Comparer.Default) for you.

However, if you want to provide sorting or comparison capability for your custom objects, you must implement either or both of these interfaces. Searching And Sorting Arrays In C# - C# Tutorials. Lambda Expressions (C# Programming Guide) A lambda expression is an anonymous function that you can use to create delegates or expression tree types.

Lambda Expressions (C# Programming Guide)

By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions. delegate int del(int i); static void Main(string[] args) { del myDelegate = x => x * x; int j = myDelegate(5); //j = 25 } To create an expression tree type: using System.Linq.Expressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Expression<del> myET = x => x * x; } } } The => operator has the same precedence as assignment (=) and is right-associative.

In the previous example, notice that the delegate signature has one implicitly-typed input parameter of type int, and returns an int. (input parameters) => expression The parentheses are optional only if the lambda has one input parameter; otherwise they are required. Reference Concepts. C# Best Practices - Dangers of Violating SOLID Principles in C# As the process of writing software has evolved from the theoretical realm into a true engineering discipline, a number of principles have emerged.

C# Best Practices - Dangers of Violating SOLID Principles in C#

And when I say principle, I’m referring to a feature of the computer code that helps maintain the value of that code. Pattern refers to a common code scenario, whether good or bad. For example, you might value computer code that works safely in a multi-threaded environment. You may value computer code that doesn’t crash when you modify code in another location. Indeed, you might value many helpful qualities in your computer code, but encounter the opposite on a daily basis.

There have been some fantastic software development principles captured under the SOLID acronym—Single responsibility, Open for extension and closed for modification, Liskov substitution, Interface segregation, and Dependency injection. The SOLID acronym and the principles encompassed within did not originate with me. The Single Responsibility Principle.

Threading in C# - Free E-book. LINQ Secrets Revealed: Chaining and Debugging. LINQ has the capabilities of providing a great productivity boost.

LINQ Secrets Revealed: Chaining and Debugging

LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques, but Michael is on hand to explain and make suggestions. This article is for .NET developers who have not used LINQ, LINQ users who have not used LINQPad, and LINQPad users who have not used LINQPad Visualizer. (Some familiarity with LINQ is assumed though.)

I take you beyond the basic concept of a LINQ query and reveal the simple techniques for creating LINQ chains, softly introducing the notion with analogous ideas in Unix and in .NET programming in general. The Unix Origins: Command Pipelining The concept of a software pipeline is not a C# innovation. #2782 - Thinking about agile (small 'a') software development, patterns and practices for building Microsoft .NET applications. Tuesday, August 19, 2008 – 2:10 pm Last night I was playing around with a vector class that’s part of a scientific computation code I’ve been working on.

#2782 - Thinking about agile (small 'a') software development, patterns and practices for building Microsoft .NET applications.

It’s a long story more on that later but it means I’ve found some of my own time to write code in. Anyway… The Vector class uses the automatically implemented properties feature of C# 3.0: public class Vector { public double X { get; set; } public double Y { get; set; } public double Z { get; set; } // ... } I was concerned that the property getters and setters were adding overhead to my class. Looking at the generated code So the best way to figure this out is to look at the code that gets generated. Public class MyClass { public int A { get; set; } public int C; } I’m using property get here but the discussion applies to any small method you hope the compiler will move inline. Running this from the debugger and looking at the disassembly shows the following code. Aggressive Inlining in the CLR 4.5 JIT. Inlining is an important optimization that allows compilers to eliminate the cost of method calls in situations where the method call overhead is more significant than the method body itself.

Aggressive Inlining in the CLR 4.5 JIT

The CLR JIT uses inlining conservatively, but features some nice tricks such as interface method call inlining – this was one of the first things I covered on this blog, almost five years ago. The limitations on JIT inlining are not known precisely, but some criteria have been announced previously (in 2004!). Namely, the JIT won’t inline: Methods marked with MethodImplOptions.NoInliningMethods larger than 32 bytes of ILVirtual methodsMethods that take a large value type as a parameterMethods on MarshalByRef classesMethods with complicated flowgraphsMethods meeting other, more exotic criteria.

MVC interview questions with answers. Download MVC.zip - 1.1 MB Table of contents Disclaimer Reading these MVC interview questions does not mean you will go and clear MVC interviews.

MVC interview questions with answers

The purpose of this article is to quickly brush up your MVC knowledge before you go for MVC interviews. C# Regular Expressions Cheat Sheet. Building COM Objects in C# - C# Help