Archive for the ‘ASP.NET/C#’ Category

C# – Get a Random Number Between x and y

Friday, October 31st, 2008

Here’s a quick function for getting random numbers in C#:

    Random rnd = new Random();
    protected int GetRandomInt(int min, int max)
    {
        return rnd.Next(min,max);
    }

    int myInt = GetRandomInt(5, 1000); //gives in random integer between 5 & 1000

Notice that you have to declare your instance of the Random class outside of the GetRandomInt function if you are going to be running this in a loop.

(more…)

Popularity: 28%

ASP.NET – C# – Emulating the VB Control Array – Pt. 1

Wednesday, October 29th, 2008

For you veterans of VB6, the control array probably became an old friend, or at least an annoying neighbor if you didn’t like them.  You couldn’t help run across the concept in VB6 because every time you copy and pasted a control for the first time, you got asked if you wanted to create a control array.

(more…)

Popularity: 29%

C#: Convert Double to Integer…and other conversions

Wednesday, October 1st, 2008

Type conversions and casting in C# are so whack!  Microsoft created the System.Convert class to bring some sanity and predictability to converting from one type to another in C#.  Without further ado, to convert a Double to an Integer, you can use:   int myInt = System.Convert.ToInt32(myDouble);

The System.Convert class has the following methods: (more…)

Popularity: 41%

ASP.Net C# – PHP Equivalents

Wednesday, September 17th, 2008

ASP.netphp_snow_2008

(more…)

Popularity: 8%

ASP.NET/C#: Convert HTML Colors to System.Drawing.Color

Wednesday, May 14th, 2008

HTML colors come in all sorts of flavors: hexadecimal (#0066ff), named colors (e.g. LightSkyBlue…here’s the link).

Many people may be very comfortable with working with HTML colors, so if you’re in C# and needing to get the .Net equivalent, you can translate directly from HTML colors with System.Drawing.ColorTranslator.FromHtml(). Here’s the usage: (more…)

Popularity: 13%