TL
TL

C# .NET Replace several different chars with strings

Can use this for escaping XML values, etc.

Tim Leffelman

Programmer, Engineer

August 15, 2017

The String.Replace() function can be used to replace all instance one character with another character ( String.Replace(char, char) ), or all instance of one substring with another string ( String.Replace(char, char) ). But, it is sometimes necessary to replace all instance of several different characters with a different string for each of . . .

Read More

C# .NET Null-checking params array

Do you need to null check a "params" array?

Tim Leffelman

Programmer, Engineer

August 02, 2017

The C# programming language allows for the creation of methods that take an arbitrary number of arguments via the params keyword. Although I have used that feature many times, and null-checked the array every time, I have never really stopped to think about whether the array is or is not null,until now. Is it necessary to null-check the . . .

Read More

C# .NET Create KeyValuePairs and Tuples the Easy Way 'a'.Tpl("ABC")

More with Extension Methods and Implied Generic Arguments

Tim Leffelman

Programmer, Engineer

August 01, 2017

I have previously written an article entitled "C# .NET -- Implied Generics in Extension Methods:
A Really Cool Way to Raise Events". This new article extends upon that to easily create Tuple objects and KeyValuePair structs.

As you may recall from the mentioned article, the C# compiler has a really awesome ability to infer the . . .

Read More

C# .NET - Using an Enum to Get a Resource

Tim Leffelman

Programmer, Engineer

July 04, 2017

There are a variety of reasons one might want to get a resource associated with an enum element. For example, it might be necessary to find an error message to display to a user or return in a web service call. Or, perhaps you need to find an icon associated with a status, etc. This article shows how to find a string from a resource file . . .

Read More

C# .NET Enum, Constant and Static ReadOnly

Enums Can Behave Like Constants

Tim Leffelman

Programmer, Engineer

June 23, 2017

The C# .NET language has constants, and it has variables. A constant is essentially a value that is known at compile-time, whereas a variable is essentially a placeholder of a specific type for a value that can change at runtime. An enum is a bit of an anomaly because it defines a type with unique set of elements backed by an integer type . . .

Read More

C# .NET -- Implied Generics in Extension Methods

A Really Cool Way to Raise Events

Tim Leffelman

Programmer, Engineer

February 09, 2017

I have previously written an article on extensions methods, which included some information about using generics with extension methods. Since that time, I have stumbled across something I did not previously realize:

If the compiler can figure out the generic type from one of the parameters passed into the extension method, you do not have . . .

Read More

.NET Interlocked Operations

System.Threading.Interlocked Class

Tim Leffelman

Programmer, Engineer

February 09, 2017

In a multi-threaded application, synchronization is key to protect data integrity. There are numerous ways to accomplish data synchronization in .NET and C#, such as the commonly used System.Threading.Monitor .NET Framework class and corresponding C# lock statement. But, when it comes to super-fast synchronization, nothing beats the . . .

Read More

Archive
  Subscribe by Email and Never Miss a Post