AES Cryptography

Contains the code for AES encryption and decryption in C#. 1: public byte [] EncryptText(string plainData) 2: { 3: RijndaelManaged rij = new RijndaelManaged(); 4: 5: rij.GenerateKey(); 6: _key = rij.Key; 7:  8: rij.GenerateIV(); 9: _intializationVector = rij.IV; 10:  11: ICryptoTransform encryptor = rij.CreateEncryptor(_key, _intializationVector); 12:  13: using (MemoryStream msEncrypt = new MemoryStream()) 14: {... Continue Reading →


UI Updates – Part 1

Updating the UI is a problem and it is tricky. There are very few simple rules to follow. Let’s see Here we’ll see  some smart ways to perform UI updates on Console applications, Windows Forms, WPF, ASP.NET, Silverlight, Windows Phone and Windows Store apps. Console Applications Do they have UI ? No. But we’ll check... Continue Reading →


checked and unchecked keywords in C#

This post explains about checked and unchecked keywords in C#. In arithmetic calculations when constants are involved compiler detects the overflows in the data types. For example look at the following code. 1: // int range is from -2,147,483,648 to 2,147,483,647 2: int i = 2147483647 + 10; The above will generate a compile time... Continue Reading →


Detecting the Windows Phone Theme Background Color

We often need to detect the WP background theme color to switch the color schemes of our apps. This is very useful when we utilize the application bar and have some metro icons in our app. In built WP apps have this feature and switch between different icons. For example when you use the Messaging... Continue Reading →


Extension Methods

Extension methods in C# is a great way to add functionality to a closed class. Here the word ‘closed’ refers to both the sealed ones and the classes which you do not have the access to their source code. Some can argue if we can actually add a method to a sealed class then it... Continue Reading →


Silverlight Dispatcher

Threading in Silverlight is simple and have very few classes and limited functionality. In Silverlight we rarely go for the threading since the platform itself is asynchronous. Click to read how to do asynchronous programming in C# 5.0 In Silverlight the  main thread is incorporated with the Dispatcher, and we can use the BeginInvoke method... Continue Reading →


Adapter Pattern

Adapter pattern is often mentioned as wrapper in normal convention. It is a pattern which introduces loose coupling when creating a middle interface between two unmatched types. The name itself, self describes itself.  Think we have a class which renders a dataset on the screen. So we’ve a working class like this. class Renderer {... Continue Reading →


Singleton Pattern

Singleton pattern is a simple design pattern in software practice and sometimes considered as an anti-pattern due its tight coupling nature. A very simple non thread safe implementation of the Singleton pattern would be like this. Singleton non thread safe class Singleton {   privatestatic Singleton _instance;   private Singleton()   {     Console.WriteLine("Singleton instantiated");... Continue Reading →


Sending Email from C#

Pure code is here. You can just copy and use it, and you can understand easily from the comments. string to = ""; // here the username can be any address // this is the address that the reciever will reply to when he/she hits the Reply button // this doesn't have to be the... Continue Reading →


Powered by

Up ↑

%d bloggers like this: