Thursday, April 9, 2009

AddThis

AddThis is a really great sharing tool for social networking.

ViewState, Twins, and Triplets!

This is a great article on ViewState and how it works that I found after a co-worker made a comment about optimizing our project by disabling the ViewState property on some of our project's web page controls.

public string NavigateUrl
{
get
{
string text = (string) ViewState["NavigateUrl"];
if (text != null)
return text;
else
return string.Empty;
}
set
{
ViewState["NavigateUrl"] = value;
}
}

(You can view the decompiled source code for a .NET assembly by using a tool like Reflector.)

So when a page control's properties are accessed, as is the case with a HyperLink's NavigateUrl property, the ViewState is actually what gets checked because it saves a snapshot of each control's persisting data. The ViewState is of type System.Web.UI.StateBag, and it stores name-value pairs for all of the page's controls, and can be accessed syntactically the same way in which a Hashtable would.

The article also highlighted two (detestably adorable) classes, the Pair and Triplet classes!

"The Pair and Triplet are two classes found in the System.Web.UI namespace, and provide a single class to store either two or three objects. The Pair class has properties First and Second to access its two elements, while Triplet has First, Second, and Third as properties."

Although I personally would have named the Pair class as the Twin class instead. Oh well.

Thursday, April 2, 2009

incomparably simple compare to example because I can never remember


using System;

class Program
{
static void Main()
{
string a = "a"; // 1
string b = "b"; // 2

int c = 0;

// When a is SMALLER than b
c = a.CompareTo(b);
Console.WriteLine(c);
// -1

// When b is BIGGER than a
c = b.CompareTo(a);
Console.WriteLine(c);
// 1
}
}

Tuesday, December 23, 2008

oh yelp...

"You may or may not end up with someone's tongue down your throat when the clock strikes midnight,..."

Friday, December 19, 2008