Export (0) Print
Expand All

Parity Enumeration

Specifies the parity bit for a SerialPort object.

Namespace:  System.IO.Ports
Assembly:  System (in System.dll)

public enum Parity

Member nameDescription
EvenSets the parity bit so that the count of bits set is an even number.
MarkLeaves the parity bit set to 1.
NoneNo parity check occurs.
OddSets the parity bit so that the count of bits set is an odd number.
SpaceLeaves the parity bit set to 0.

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.

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.

// 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);
}

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft