Category: C#

Simple encryption and decryption of a string in c#

20 August, 2010 (12:32) | Cryptography, Security, Snippets, Programming, C#, Code

Here are some routines which are designed for simple use of Rijndael in C#. I’ve combined a test function in the class for simplicity of showing it’s use.

private static byte[] salt = Encoding.ASCII.GetBytes(”somerandomstuff”);

public static string Encrypt(string plainText, string […]

Solving the Towers of Hanoi puzzle in C#

4 August, 2009 (18:45) | .Net, Programming, C#, Computer Science

I thought this would be a fun little exercise to try. This puzzle is generally used to teach recursion in CS classes, but I have never actually tried to implement it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TowersOfHanoiCs
{
class Program
{
static List […]

The difference between Java’s “final” and C#’s “const”

15 February, 2008 (20:01) | .Net, Java, C#, Computer Science

Final in Java is used to declare a class that can’t be subclassed, a method that can’t be overridden, or …
A final variable means the value won’t change, but the value can still be determined at run time:

final int i;
if ( j > 0 ){
i =1;
} else {
i = […]

Passing immutable types by reference in Java and C#

12 October, 2007 (18:26) | Java, C#, Computer Science

To many, it should be obvious what the following code prints:

public static void main(String[] args){
int x=0;
SomeMethod(x);
System.out.println(x);
}

protected static void SomeMethod(int x){
x=1;
}

The code prints 0, because “int” is a native type and is passed by value. […]

Does string interning in C# guarentee you only get one copy of a static value?

19 September, 2007 (22:15) | .Net, C#, Computer Science

Of course the answer is no, otherwise it wouldn’t be a very interesting post. The concept of interning is an attempt to save memory by allocating static values which match exactly to the same memory location, without regard to where they’re used in the application. But here’s in instance where it doesn’t quite […]