Parity 枚举


指定 SerialPort 对象的奇偶校验位。Specifies the parity bit for a SerialPort object.

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


Even 2

设置奇偶校验位,使位数等于偶数。Sets the parity bit so that the count of bits set is an even number.

Mark 3

将奇偶校验位保留为 1。Leaves the parity bit set to 1.

None 0

不发生奇偶校验检查。No parity check occurs.

Odd 1

设置奇偶校验位,使位数等于奇数。Sets the parity bit so that the count of bits set is an odd number.

Space 4

将奇偶校验位保留为 0。Leaves the parity bit set to 0.


下面的代码示例向控制台显示Parity枚举的可能值, 然后提示用户选择一个值。The following code example displays the possible values of the Parity enumeration to the console, then prompts the user to choose one. 此代码示例是为SerialPort类提供的更大代码示例的一部分。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)

    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


设置串行端口连接的Parity属性时, 请使用此枚举。Use this enumeration when setting the Parity property for a serial port connection.

奇偶校验是一种错误检查过程, 在此过程中, 1 的值必须始终是相同的, 无论是在传输时不出错的每个位组。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.