StringExtensionsToEnumTEnum Method

Tries to convert the specified string to an Enum value of TEnum type.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.1.0
C#
public static TEnum? ToEnum<TEnum>(
	this string? s,
	bool definedOnly = false
)
where TEnum : struct, new()

Parameters

s  String
The string to convert.
definedOnly  Boolean  (Optional)
If , the result can only be a defined value in the specified TEnum type. If , the result can be a non-defined value, too.

Type Parameters

TEnum
The type of the Enum.

Return Value

NullableTEnum
A non- value if the conversion was successful; otherwise, .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also