Skip to main content

Posts

Showing posts from May, 2016

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....