C# Method Expression-bodied Syntax

Please see my other C# articles. Simplify single-statement methods When writing methods with contain only a single statement, you can avoid curly braces and a return statement by using expression-bodied syntax. Similar to lambda expression, append the “fat arrow” after the method signature and provide the single statement. Note: Less space and code is required to perform…

C#: Method named parameters

Please see my other C# articles. Improve readability when invoking method parameters In this article, I’ll demonstrate how to explicitly invoke method parameters and optionally change the parameter order. In the following overloaded method, I have two pameters. When I invoke this method, I want to clarify which argument is sent to the multiplier verses the array…

C#: String Interpolation

Please see my other C# articles. Use strings in an easier, less-error prone way In this article I’ll demonstrate how to integrate string values into a statement which reduces potential errors and produces more readable statements. Note: Using interpolation, there’s no need to open/close variables within the statement. Also, to use interpolation, you must precede the statement…

C#: Method optional parameter

Please see my other C# articles. Declare default value for a parameter to make it optional In this article I’ll demonstrate how to make method parameters optional to add flexibility when invoking methods. To make a parameter optional, simply declare a default value for it in the signature. Then, during invocation, any parameters which don’t receive a…

C#: Method params keyword

Please see my other C# articles. Using params to receive unknown quantity of arguments In this article, I’ll demonstrate how to configure a method signature to receive a amount of arguments unknown at design time. I’ll begin with an array of lottery picks I want to display on the screen. Now, I want a method which receives…

Visual Studio: .NET Garbage Collection

View the garbage collection in action In this article I will demonstrate the .NET garbage collection working. First, I’ll setup a loop which instantiates 10,000,000 Person objects using named parameters. Next, I’ll set a breakpoint at the curly brace immediately below (outside of) the for() loop. Now I’ll invoke the Diagnostic tools (Debug -> Windows…

MVC: Passing Query String Values in a View

Please see my other MVC articles. Building Links from Model Data This article illustrates how to build a link within an MVC view which passes model data as a query string variable. First, I begin with my “model” statement exposing my RaveUser model’s properties. Next, I provide an ActionLink() statement with text for the link (“Reload All…

MVC: Parsing a URL

Please see my other MVC articles. Using URL Properties in a page MVC, ASP.NET, and IIS provide a very easy and effective way to interpret data contained within the current URL.By simply creating a method with the appropriately named parameters (order doesn’t matter), that method may parse data contained within the URL.

MVC: Conditionally Display View link

Please see my other MVC articles. Displaying Links Based on IF Logic This article illustrates how to conditionally display a link within an MVC based on the results of an IF statement. As you can see in my View’s HTML, I am displaying a “Home” link and then, if the current user is part of the Administrator…

MVC: Conditional Redirect to View

Please see my other MVC articles. Redirecting Users to a New Page Based on IF Logic Similar to the article (link) MVC: Conditionally Display View link, this article illustrates how to use condition logic to change the user experience by using the controller’s default function to test if the current user is part of the Administrator role,…