Parity Parity Parity Parity Enum

Definition

Specifies the parity bit for a SerialPort object.

public enum class Parity
public enum Parity
type Parity = 
Public Enum Parity
Inheritance

Fields

Even Even Even Even 2

Sets the parity bit so that the count of bits set is an even number.

Mark Mark Mark Mark 3

Leaves the parity bit set to 1.

None None None None 0

No parity check occurs.

Odd Odd Odd Odd 1

Sets the parity bit so that the count of bits set is an odd number.

Space Space Space Space 4

Leaves the parity bit set to 0.

Examples

The following code example displays the possible values of the Parity enumeration to the console, then prompts the user to choose one. This code example is part of a larger code example provided for the SerialPort class.

static Parity SetPortParity(Parity defaultPortParity)
{
    String^ parity;

    Console::WriteLine("Available Parity options:");
    for each (String^ s in Enum::GetNames(Parity::typeid))
    {
        Console::WriteLine("   {0}", s);
    }
    
    Console::Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString());
    parity = Console::ReadLine();

    if (parity == "")
    {
        parity = defaultPortParity.ToString();
    }

    return (Parity)Enum::Parse(Parity::typeid, parity);
}
// Display PortParity values and prompt user to enter a value.
public static Parity SetPortParity(Parity defaultPortParity)
{
    string parity;

    Console.WriteLine("Available Parity options:");
    foreach (string s in Enum.GetNames(typeof(Parity)))
    {
        Console.WriteLine("   {0}", s);
    }

    Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), true);
    parity = Console.ReadLine();

    if (parity == "")
    {
        parity = defaultPortParity.ToString();
    }

    return (Parity)Enum.Parse(typeof(Parity), parity, true);
}
' Display PortParity values and prompt user to enter a value.
Public Shared Function SetPortParity(defaultPortParity As Parity) As Parity
    Dim parity As String

    Console.WriteLine("Available Parity options:")
    For Each s As String In [Enum].GetNames(GetType(Parity))
        Console.WriteLine("   {0}", s)
    Next

    Console.Write("Enter Parity value (Default: {0}):", defaultPortParity.ToString(), True)
    parity = Console.ReadLine()

    If parity = "" Then
        parity = defaultPortParity.ToString()
    End If

    Return CType([Enum].Parse(GetType(Parity), parity, True), Parity)
End Function

Remarks

Use this enumeration when setting the Parity property for a serial port connection.

Parity is an error-checking procedure in which the number of 1s must always be the same - either even or odd - for each group of bits that is transmitted without error. In modem-to-modem communications, parity is often one of the parameters that must be agreed upon by sending parties and receiving parties before transmission can take place.

Applies to