You can take a look at its source code and see the constructors and submitted definitions.
You will see that all important properties, including PortName , BaudRate , DataBits , Parity and StopBits have a default value, which, if they are not in the constructor arguments, will be used for them by default.
In addition, some other important properties also have default values, although they are not present in the constructors, but in some cases their default value may not be very good.
For example, for HandShake , the default value is Handshake.None; while you may want to set it for Handshake.XOnXOff , Handshake.RequestToSend or Handshake.RequestToSendXOnXOff . For this particular property, you can refer to Hans comments .
Look at the constructors:
public SerialPort(System.ComponentModel.IContainer container) { container.Add(this); } public SerialPort() { } // Non-design SerialPort constructors here chain, //using default values for members left unspecified by parameters public SerialPort(string portName) : this (portName, defaultBaudRate, defaultParity, defaultDataBits, defaultStopBits) { } public SerialPort(string portName, int baudRate) : this (portName, baudRate, defaultParity, defaultDataBits, defaultStopBits) { } public SerialPort(string portName, int baudRate, Parity parity) : this (portName, baudRate, parity, defaultDataBits, defaultStopBits) { } public SerialPort(string portName, int baudRate, Parity parity, int dataBits) : this (portName, baudRate, parity, dataBits, defaultStopBits) { } public SerialPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits) { this.PortName = portName; this.BaudRate = baudRate; this.Parity = parity; this.DataBits = dataBits; this.StopBits = stopBits; }
And here are these fields and default value definitions:
// ---------- default values -------------* private const int defaultDataBits = 8; private const Parity defaultParity = Parity.None; private const StopBits defaultStopBits = StopBits.One; private const Handshake defaultHandshake = Handshake.None; private const int defaultBufferSize = 1024; private const string defaultPortName = "COM1"; private const int defaultBaudRate = 9600; private const bool defaultDtrEnable = false; private const bool defaultRtsEnable = false; private const bool defaultDiscardNull = false; private const byte defaultParityReplace = (byte) '?'; private const int defaultReceivedBytesThreshold = 1; private const int defaultReadTimeout = SerialPort.InfiniteTimeout; private const int defaultWriteTimeout = SerialPort.InfiniteTimeout; private const int defaultReadBufferSize = 4096; private const int defaultWriteBufferSize = 2048; private const int maxDataBits = 8; private const int minDataBits = 5; private const string defaultNewLine = "\n"; private const string SERIAL_NAME = @"\Device\Serial";
// --------- members supporting exposed properties ------------* private int baudRate = defaultBaudRate; private int dataBits = defaultDataBits; private Parity parity = defaultParity; private StopBits stopBits = defaultStopBits; private string portName = defaultPortName; // ASCII is default encoding for modem communication, etc. private Encoding encoding = System.Text.Encoding.ASCII; private Decoder decoder = System.Text.Encoding.ASCII.GetDecoder(); private int maxByteCountForSingleChar = System.Text.Encoding.ASCII.GetMaxByteCount(1); private Handshake handshake = defaultHandshake; private int readTimeout = defaultReadTimeout; private int writeTimeout = defaultWriteTimeout; private int receivedBytesThreshold = defaultReceivedBytesThreshold; private bool discardNull = defaultDiscardNull; private bool dtrEnable = defaultDtrEnable; private bool rtsEnable = defaultRtsEnable; private byte parityReplace = defaultParityReplace; private string newLine = defaultNewLine; private int readBufferSize = defaultReadBufferSize; private int writeBufferSize = defaultWriteBufferSize;