Formatting/parsing for a specific culture

Sometimes you may want to use a specific format for formatting and parsing of textual data.  The easiest way to do this is to select a specific culture and use that with formatting and parsing methods.  Unfortunately, the CultureInfo constructor that just takes the name of the culture defaults to accepting any overrides the current user has set in Regional and Language Options. For example, if in Regional and Language Options you have English (United States) selected and you’ve changed the currency symbol to be something other than the dollar sign ($), the following won’t use the dollar sign:     … Continue reading Formatting/parsing for a specific culture

Bridges and Factories

In my previous post, I talked about Dependency Injection (DI).  One implementation of DI is using interface-oriented design to abstract a class from an injected dependency via an interface.  This is one possible implementation of the Bridge pattern.  Depending only upon an interface and classes to implement that interface opens up some very interesting possibilities. The tried-and-true means of creating an object is to simply directly use it’s constructor, for example:         IPerson person = new Employee(“Peter”, “Ritchie”); This is nice and simple; but we’re still coupled to Employee despite using an IPerson object thereafter.  The above code hasn’t truly eliminated the … Continue reading Bridges and Factories

BigInteger is not in .NET Framework 3.5

A while back Inbar Gazit blogged about a new (at the time) Orcas type System.Numeric.BigInteger.  BitInteger is intended to represent an integer of “arbitrary” precision–from 1 digit to 2,147,483,647 digits.  “Arbitrary” because realisitically approaching 2,147,483,647 will not have enough memory to store the integer. For whatever reason, this type didn’t make it into the RTM version of .NET 3.5–it’s actually internal, not public.  I don’t know why, Inbar didn’t follow up.

Dependency Injection

Dependency injection (DI) is a form of inversion of control.  There seems to be a tendency in some circles to refer to dependency injection as inversion of control (IoC).  Dependency injection is a form of abstraction by removing physical dependencies between classes and potentially assemblies.  This abstraction can have many different motives.  One motive is for Aspect Oriented Software Development (ASOD) where you’re abstracting shared (or cross-cutting) concerns into independent classes.  Another motive is for Test-Driven Development (TDD) where you want to be able to test each class independently of its dependencies–in which case injected dependencies are “mocked”–technically this is … Continue reading Dependency Injection

New Warning CS1060 in C# 3 (Visual Studio 2008)

Recompiling C# 2 (Visual Studio 2005) code in C# 3 (Visual Studio 2008), you may incounter a new warning that didn’t used to ocur: Warning CS1060: Use of        possibly unassigned field ‘fieldName’. Struct instance variables are initially unassigned if struct is unassigned. Dealing strictly with syntax, C# let’s you declare a value type (struct) with a reference member, for example: namespace Examples{    using System.Drawing;    public static class Program    {        public static void Main()        {            LabelEntry labelEntry;            labelEntry.Location.Point.X = 0;        }    }     public struct LabelEntry    {        public LabelLocation Location;        public String Label;    … Continue reading New Warning CS1060 in C# 3 (Visual Studio 2008)