Category: .NET

Class and New Constraints with Generic Methods

The Need for Generic Methods With Constraints Consider a CommandLineHandler ` class that parses a command line string and populates an arbitrary object with the command line data.  Each property on the arbitrary object would correspond to a switch on the command line and, using reflection, the idea would be to initialize the data with […]

How-to: Calling Web Services Using Basic Authentication

How-to: WebMethods Call Using Basic Authentication I recently made a web services call into WebMethods using basic authentication.  This authentication meant that we needed to modify the WSDL generated classes to handle the authentication. Here’s how it works.  I add a reference to the Web Service (Visual Studio generates the client code for calling the web service).  Then, […]

How-to: Converting Command Line String to ARGS

Converting Command Line String to ARGS Walk-through In testing a command line I recently wanted to verify that the string passed on the command line was converted to the args[]` array that was passed to `Main(string[] args).  For example, given the command line Compress.exe /v:ReallyMakeItSmall myfile.txt "Read ME.txt" What does the call to Main(string args[]) […]

Beware of Inequalities With Floating Point Types

Inaccuracies of Floats I have been playing around with the inaccuracies of floats and decided to share some of the simplest comparisons that might surprise folks that use the equality comparisons of floats indiscriminately. The following code listing pretty much captures the issues: using System.Diagnostics; … decimal decimalNumber = 4.2M; double doubleNumber1 = 0.1F * […]

Declaring Generic Interfaces With C#

C# Generics Implementation With the C# generics implementation that is currently under proposal it will be possible to declare generic interfaces, not just generic classes.  This is really cool as it avoids the ambiguity associated with returning an object such as in the System.Collections.IEnumerable interface.  In place of the non-generic interface we would use the generic System.Collections.Generics.IEnumerable […]

Using @ to Disambiguate Keywords from Identifiers in C#

C# Language Specification While reading the C# Language Specification today I noticed the use of the @ sign to disambiguate a keyword from an identifier.  When you do this the identifier is called a verbatim identifier.  So, for example, you could write code as follows: class @class { static void Main() { @static(false); } public […]