Thursday, May 27, 2010

Not a nullale type - C# 2008

Complete error:
Cannot convert null to 'myNameServer.myStructName' because it is a non-nullable value type

Use class instead of struct.

(temporary solution only, hopefully this post will be edited)

Enums in C#

correct usage:

class myClass
{
public enum myEnumType {Value1, Value2};
public myEnumType myEnumVariable;
}

class myOtherClass
{
public myFunction()
{
myClass foo = new myClass();
foo.myEnumVariable = myClass.myEnumType.Value1;
}
}

Monday, May 17, 2010

Number only text box - C# Express Edition

private void txt_FieldName_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
e.KeyChar = '\0';
}