Basic C# algorithms