Archive | ASP.NET/C#

random_wrong

C# – Get a Random Number Between x and y

Here’s a quick function for getting random numbers in C#: 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. “Why is this?” you ask. Well, the Random class actually generates pseudo random numbers, with the “seed” for […]

Continue Reading

C#: Convert Double to Integer…and other conversions

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: ToBoolean ToByte […]

Continue Reading
ASP.net

ASP.Net C# – PHP Equivalents

On this post, I will be collecting ASP.NET C# commands that I use frequently in PHP but I have to continually look up in the little bit of ASP.NET that I do.  PHP can be frustrating for its inconsistencies in syntax, but what is even more frustrating is when you’re trying to do something in […]

Continue Reading

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

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: System.Drawing.Color myColor = System.Drawing.ColorTranslator.FromHtml(“Red”); […]

Continue Reading

Powered by WordPress. Designed by Woo Themes