API Reference

This section provides a detailed reference for the public API of the ConsoleTables library.

ConsoleTable Class

The main class for creating and managing tables.

Constructors

  • public ConsoleTable(params string[] columns)

    • Creates a new table with the specified column headers.
  • public ConsoleTable(ConsoleTableOptions options)

    • Creates a new table using a provided ConsoleTableOptions object.

Properties

  • public IList<object> Columns { get; }

    • Gets the list of column headers.
  • public IList<object[]> Rows { get; }

    • Gets the list of rows in the table. Each object[] represents a single row.
  • public ConsoleTableOptions Options { get; }

    • Gets the options object associated with the table.
  • public int MaxWidth { get; set; }

    • Gets or sets the maximum width of a cell before its content is wrapped. Default is 40.
  • public char WordBreakDelimiter { get; private set; }

    • Gets the character used for word breaking when wrapping text. Default is a space character.

Methods

  • public ConsoleTable AddRow(params object[] values)

    • Adds a new row to the table. The number of values must match the number of columns.
  • public ConsoleTable AddColumn(IEnumerable<string> names)

    • Adds new columns to the table.
  • public ConsoleTable Configure(Action<ConsoleTableOptions> action)

    • Configures the table's options using an action.
  • public ConsoleTable SetWordBreakDelimiter(char delimiter)

    • Sets the delimiter for word breaking.
  • public void Write(Format format = ConsoleTables.Format.Default)

    • Writes the formatted table to the output target (default is Console.Out).
  • public override string ToString()

    • Returns the table as a string in the Default format.
  • public string ToMarkDownString()

    • Returns the table as a string in Markdown format.
  • public string ToMinimalString()

    • Returns the table as a string in the Minimal format.
  • public string ToStringAlternative()

    • Returns the table as a string in the Alternative format.

Static Factory Methods

  • public static ConsoleTable From<T>(IEnumerable<T> values)

    • Creates a table from a collection of objects. Public properties of T are used as columns.
  • public static ConsoleTable From(DataTable dataTable)

    • Creates a table from a System.Data.DataTable.
  • public static ConsoleTable FromDictionary(Dictionary<string, Dictionary<string, object>> values)

    • Creates a table from a nested dictionary.
  • public static ConsoleTable From(Object[][] values)

    • Creates a table from a 2D object array. The first row is assumed to be the header.

ConsoleTableOptions Class

Container for table configuration options.

Properties

  • public IEnumerable<string> Columns { get; set; }

    • The column headers for the table.
  • public bool EnableCount { get; set; }

    • If true, a "Count: X" footer is displayed. Default is true.
  • public Alignment NumberAlignment { get; set; }

    • Sets the alignment for numeric types when using From<T>. Default is Alignment.Left.
  • public TextWriter OutputTo { get; set; }

    • The TextWriter to which the table will be written. Default is Console.Out.

Format Enum

Specifies the rendering style for the table.

  • Default: Standard style with - and |.
  • MarkDown: GitHub-Flavored Markdown table.
  • Alternative: Style with + at border intersections.
  • Minimal: Style with no vertical borders and only a header underline.

Alignment Enum

Specifies the text alignment within a cell.

  • Left
  • Right