Database ExtensionsTo Char Method
This is used to convert a string value to a nullable Char by returning null if the string is
null or empty or the first character of the string if not.
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
If the value is null or an empty string, this returns null. If not, it returns the first character of the string.
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static char? ToChar(
this string? value
)VB
<ExtensionAttribute>
Public Shared Function ToChar (
value As String
) As Char?C++
public:
[ExtensionAttribute]
static Nullable<wchar_t> ToChar(
String^ value
)F#
[<ExtensionAttribute>]
static member ToChar :
value : string -> Nullable<char> Parameters
- value String
- The value to check
Return Value
NullableCharIf the value is null or an empty string, this returns null. If not, it returns the first character of the string.
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).Example
C#
using var dataContext = new MyDbContext();
dataContext.spAddName(txtLastName.Text, txtFirstName.Text.NullIfWhiteSpace(),
txtRace.Text.ToChar(), txtSex.Text.ToChar(),
dtpDOB.BindableValue.ToNullable<DateTime>());