How to query a DataTable using LINQ in C# and VB.NET

To query a DataTable using LINQ in C# and VB.NET you can use the snippet below.
In order to use the snippet, you need to reference System.Data.DataSetExtensions.

Sample C#

var resultData = (from myDataRow in myDataTable.AsEnumerable() where myDataRow.Field<Int32>("Fieldname") == 1 select myRow);

Sample VB.NET

Dim resultData = (From myDataRow In myDataTable.AsEnumerable() Where myDataRow.Field(Of Int32)("Fieldname") = 1myRow)

How to convert a string to enum in Java

To convert a string to enum in Java you can use the following snippet.

Considering the following enum.

Sample Java

public enum Testenum {
  One,Two,Three,Four
}

you can cast an string to enum like this:

Sample Java

Testenum.valueOf("Two");

How to get Enum by Descritption Attribute in C# and VB.NET

To get Enum by Descritption Attribute in C# and VB.NET you can use the following snippet.

Sample C#

public static T GetEnumFromDescriptionAttribute<T>(string description)
{
	var type = typeof(T);
	if (!type.IsEnum) throw new InvalidOperationException();
	foreach (var fieldInfo in type.GetFields())
	{
		var descriptionAttribute = Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
		if (descriptionAttribute != null)
		{
			if (descriptionAttribute.Description != description) continue;
			return (T)fieldInfo.GetValue(null);
		}
		if (fieldInfo.Name != description) continue;
		return (T)fieldInfo.GetValue(null);
	}
	return default(T);
}

Sample VB.NET

Public Shared Function GetEnumFromDescriptionAttribute(Of T)(description As String) As T
	Dim type = GetType(T)
	If Not type.IsEnum Then
		Throw New InvalidOperationException()
	End If
	For Each fieldInfo As var In type.GetFields()
		Dim descriptionAttribute = TryCast(Attribute.GetCustomAttribute(fieldInfo, GetType(DescriptionAttribute)), DescriptionAttribute)
		If descriptionAttribute IsNot Nothing Then
			If descriptionAttribute.Description <> description Then
				Continue For
			End If
			Return DirectCast(fieldInfo.GetValue(Nothing), T)
		End If
		If fieldInfo.Name <> description Then
			Continue For
		End If
		Return DirectCast(fieldInfo.GetValue(Nothing), T)
	Next
	Return Nothing
End Function