Skip to main content

Posts

Validate credit card number with Mod 10 algorithm in C#

Introduction All you know what information contains in your NIC number. But do you know what information contains in the Credit Card Number? Following article provides brief details about what information contain in your credit card and demonstrates to how to validate credit card number using mod 10 (Luhn) algorithms with C#. Background  Card Length   Typically, credit card numbers are all numeric and the length of the credit card number is between 12 digits to 19 digits.  14, 15, 16 digits – Diners Club 15 digits – American Express 13, 16 digits – Visa 16 digits - MasterCard   For more information please refer  http://en.wikipedia.org/wiki/Bank_card_number . Hidden information  Major Industry Identifier (MII)   The first digit of the credit card number is the Major Industry Identifier (MII). It designates the category of the entry which issued the card.     1 and 2 – Airlin...

Convert Data Type Using Generic using C#

Usage first: TConverter . ChangeType < T >( StringValue ); The class is below. public static class TConverter { public static T ChangeType < T >( object value ) { return ( T ) ChangeType ( typeof ( T ), value ); } public static object ChangeType ( Type t , object value ) { TypeConverter tc = TypeDescriptor . GetConverter ( t ); return tc . ConvertFrom ( value ); } public static void RegisterTypeConverter < T , TC >() where TC : TypeConverter { TypeDescriptor . AddAttributes ( typeof ( T ), new TypeConverterAttribute ( typeof ( TC ))); } } Ref: http://stackoverflow.com/questions/8625/generic-type-conversion-from-string Example of Console Application below. class Program { static void Main(string[] args) { Console.WriteLine(TConverter.ChangeType<float>("00454545458")); Console....

List of Mime Type of file in C#

private string GetFileMimeType(string extension)         {             char[] arr = extension.ToCharArray();             arr = Array.FindAll<char>(arr, (c => (char.IsLetterOrDigit(c))));             extension = new String(arr).ToLower();             Dictionary<string, string> lstMimeTypes = new Dictionary<string, string>               {                 {"ai", "application/postscript"},                 {"aif", "audio/x-aiff"},              ...

Is your code ready for the leap year?

As we enter February, it's a good time to remember that 2016 is a leap year . For most people, this may just be an interesting oddity; an extra day to work or play. But for software developers, the leap year can cause significant pain. If you are just now thinking about checking your code for leap year bugs, you better move quickly. In fact, you might already be experiencing the effects and may not even realize it! What kind of bugs might be lurking in your code? Off-by-one issues, especially around data filtering using date-range queries Unexpected or undesired behavior in user interfaces Potential for exceptions, crashes, or hanging as edge cases are encountered “Meh,” you say. “My code is just fine. We have unit tests.” “Oh really,” I say. “Do your tests properly mock the clock? Do they test edge cases including February 29 and December 31? Have you tested any low-level C++ code you might have as well as the rest of your system? Do you even know what a leap y...