RingDotNetfor Ring

Tutorials

Step-by-step lessons for people who are new to .NET. Each one explains the ideas first, then builds a small program you can run, with the real output and screenshots.

How to use the tutorials#

Every tutorial has a program in the folder samples/UsingDotNet/tutorials. Read the explanation, run the program, change it, and do the exercises at the end. The programs are real: they are tested together with the rest of the package, so the output you see here is the output you will get.

Shell
cd samples/UsingDotNet/tutorials
ring ch01_first_look.ring            # a console tutorial
ring ch10_counter.ring              # a window
ring ch10_counter.ring --selftest   # the same program checks itself and closes
Tip

You do not need to know .NET to start. If you know Ring, you can follow every tutorial. The first two pages explain the .NET words that you will meet.

Note

The lessons about NuGet packages (the chapter Libraries and packages) run dotnet publish, so they need the .NET SDK and, the first time, the internet to get the packages.

Start here#

The chapters#

The tutorials are grouped by topic. Read The basics first, in order; after that, choose the chapter that you need. The pages inside a chapter lead from one to the next, and the last page of a chapter points to the next chapter.

ChapterWhat it is about
The basicsConsole programs that use the class library: text, numbers, collections, files, JSON and XML, errors, hashing, HTTP, tasks and processes.
Text and data formatsRegular expressions, formatting, Unicode and text file encodings, comparing and escaping text, URLs, Base64 and hexadecimal, domain names, MIME types, JSON in two styles, XML and XSLT, Markdown, spelling, and two projects: a mail merge and a syntax highlighter.
Numbers, dates and moneyThe number types and their limits, rounding, big numbers, number systems, exact money, vectors, randomness and statistics, then dates, time zones, calendars, working days and cultures.
Collections and algorithmsArrays, sets and other data structures, collections for many threads, enums and identifiers, undo and queues, recursion and an expression calculator.
Files and streamsPaths, file information and disks, streams, binary files and random access, compression (GZip, ZIP, tar), file patterns, watching a folder, and projects that work on many files: a log analyzer, a duplicate finder, a backup tool, a file renamer, a file comparison and a checksum list.
Processes and performanceAsking the computer about itself, command-line tools, logging and tracing, starting and talking to other programs, tasks that wait, releasing resources, measuring speed and memory, and the Windows Registry.
Networking and the webIP addresses and networks, TCP and UDP sockets, WebSockets, HttpClient and REST, web services and small web sites, route templates, a link shortener, and e-mail messages.
SecurityHashing, encryption and signing, certificates, protecting data, logins and sessions, identities and claims, and rate limiting.
Databases and servicesSQL and Entity Framework, reports, Microsoft Access, and the services of an application: settings and configuration, caching and dependency injection.
Windows FormsWindows with controls, the keyboard and the mouse, layout, lists and grids, formatted text, the clipboard, drag and drop, dialogs, more than one window and a tray icon, printing, menus, timers, drawing, images and charts (Windows only).
WPFXAML windows, layout and styles, data binding, menus and tabs, lists and dynamic content, and animation (Windows only).
Projects with windowsComplete programs: a to-do list, Tic-Tac-Toe, a quiz, a command runner, an address book with a database, a sorting lab, a maze, an image filter lab and a chat (Windows only).
Libraries and packagesGiving Ring code to .NET (callbacks and events), reflection and expression trees, an object inspector, a library written in C#, the generic functions, and then NuGet packages and native code: a NuGet package, a QR code, Excel files, pictures, PDF files, text to speech, sound, native DLLs, and a project that uses three packages together.
Testing and releaseThe common mistakes, programs that run on more than one system, testing your programs, and giving a program to other people.

Where to start#

If you want to...Read
understand the vocabulary.NET for Ring programmers, Reading the .NET documentation
learn the class library step by stepthe chapter The basics
work with text, JSON and XMLText and data formats
calculate with numbers, dates and moneyNumbers, dates and money
read, write and pack filesFiles and streams
talk to other computers, build a web serviceNetworking and the web
store dataDatabases and services
protect data and usersSecurity
build programs with windowsWindows Forms, then WPF and Projects with windows
go deeper: callbacks, reflection, your own C# library, NuGet packagesLibraries and packages
find and fix mistakes, test and give away a programTesting and release
give your program to other peoplethe tutorial Giving your program to others

The basics#

Console programs that use the class library: text, numbers, collections, files, JSON and XML, errors, hashing, HTTP, tasks and processes. Start here and read them in order.

Text and data formats#

Regular expressions, formatting, Unicode and text file encodings, comparing and escaping text, URLs, Base64 and hexadecimal, domain names, MIME types, JSON in two styles, XML and XSLT, Markdown, spelling, and two projects: a mail merge and a syntax highlighter.

๐Ÿ”ค
Regular expressions in depthPatterns, groups, replace, split, greedy and lazy, validation.
๐Ÿ”ค
Formatting numbers and datesFormat strings: decimals, thousands, percent, patterns, alignment, dates and durations.
๐Ÿ”ค
Unicode and encodingsBytes, code points and letters; UTF-8, UTF-16 and mojibake.
๐Ÿ”ค
Text files and encodingsThe bytes of a text, the BOM, reading Latin-1 and UTF-16 files, strict UTF-8 and line endings.
๐Ÿ”ค
Comparing textOrdinal and culture comparison, StringComparer, and the Turkish i.
๐Ÿ”ค
Text readers and writersStringWriter, StringReader, capturing Console output, String.Format.
๐Ÿ”ค
EscapingThe right encoding for HTML, URLs, JavaScript, JSON, XML, regular expressions and SQL.
๐Ÿ”ค
URLs and encodingsUri, query strings, percent-encoding, relative addresses and Base64.
๐Ÿ”ค
Bytes as text: Base64 and hexBase64, the URL-safe form, hexadecimal, padding, wrong input and data URIs.
๐Ÿ”ค
International domain namesPunycode, IdnMapping and look-alike letters (homograph attacks).
๐Ÿ”ค
MIME typesFile extensions, Content-Type, Accept and content negotiation.
๐Ÿ”ค
Writing JSON as a streamUtf8JsonWriter, indentation, escaping and JsonSerializer options.
๐Ÿ”ค
JSON as a treeJsonNode: read, edit, build, merge and clone JSON.
๐Ÿ”ค
XML in depthXDocument, XPath, building and changing elements, bad XML.
๐Ÿ”ค
XSLTTurn XML into text, CSV and HTML with XslCompiledTransform.
๐Ÿ”ค
Project: Markdown to HTMLBlocks, inline formatting, regular expressions, and escaping first.
๐Ÿ”ค
A spell checkerA set of words, the edit distance table and the best suggestions.
๐Ÿ”ค
Project: mail mergeA template with fields, CSV data, Regex.Replace with a callback and a check for missing data.
๐Ÿ”ค
Project: a syntax highlighterOne regular expression with named groups, tokens, HTML spans and escaped text.

Numbers, dates and money#

The number types and their limits, rounding, big numbers, number systems, exact money, vectors, randomness and statistics, then dates, time zones, calendars, working days and cultures.

Collections and algorithms#

Arrays, sets and other data structures, collections for many threads, enums and identifiers, undo and queues, recursion and an expression calculator.

Files and streams#

Paths, file information and disks, streams, binary files and random access, compression (GZip, ZIP, tar), file patterns, watching a folder, and projects that work on many files: a log analyzer, a duplicate finder, a backup tool, a file renamer, a file comparison and a checksum list.

๐Ÿ“
Paths and the environmentPath.Combine, special folders, valid names and environment variables.
๐Ÿ“
File informationFileInfo: size, times, attributes, read-only files, copying and temporary files.
๐Ÿ“
Disks and free spaceDriveInfo, the sizes of a disk, will it fit, and sizes for people.
๐Ÿ“
Streams and compressionMemoryStream, StreamWriter, GZip, and one pattern for memory and files.
๐Ÿ“
Binary filesBinaryWriter and BinaryReader, a file format, a hex dump, little endian.
๐Ÿ“
Random access and file locksFixed-size records, Seek, changing a record in place, SetLength and FileShare.
๐Ÿ“
Copying a big fileRead and write in pieces with a byte buffer, progress, cancel and a checksum.
๐Ÿ“
What kind of file is it?Magic numbers, a signature table, text or binary, and names that tell a lie.
๐Ÿ“
CompressionGZip, Deflate and Brotli streams, sizes, round trips and a .gz file.
๐Ÿ“
ZIP archives in memoryZipArchive on a MemoryStream: entries, levels and updates.
๐Ÿ“
Tar archivesCreate, list, read and unpack tar files.
๐Ÿ“
File patterns (globbing)**/*.ring, include and exclude rules, matching lists of paths.
๐Ÿ“
Watching a folderFileSystemWatcher: created, changed, renamed and deleted files, with a child program.
๐Ÿ“
Project: a log analyzerFiles, regular expressions, dictionaries, LINQ and a JSON report in one program.
๐Ÿ“
Project: duplicate filesFolders, content hashes and a dictionary find the copies.
๐Ÿ“
Project: a backup toolZip by date, keep the newest few, restore and verify.
๐Ÿ“
Project: rename many filesRules, a preview, conflict checks, renaming and undo with a log.
๐Ÿ“
Project: compare two filesThe longest common subsequence, a diff with context, and a similarity in percent.
๐Ÿ“
Project: check that files did not changeSHA-256 checksums in the sha256sum format, verify, and protecting the list.

Processes and performance#

Asking the computer about itself, command-line tools, logging and tracing, starting and talking to other programs, tasks that wait, releasing resources, measuring speed and memory, and the Windows Registry.

Networking and the web#

IP addresses and networks, TCP and UDP sockets, WebSockets, HttpClient and REST, web services and small web sites, route templates, a link shortener, and e-mail messages.

Security#

Hashing, encryption and signing, certificates, protecting data, logins and sessions, identities and claims, and rate limiting.

Databases and services#

SQL and Entity Framework, reports, Microsoft Access, and the services of an application: settings and configuration, caching and dependency injection.

Windows Forms#

Windows with controls, the keyboard and the mouse, layout, lists and grids, formatted text, the clipboard, drag and drop, dialogs, more than one window and a tray icon, printing, menus, timers, drawing, images and charts (Windows only).

๐ŸชŸ
Your first windowA form, a label, a button, an event โ€” with and without the helper functions.
๐ŸชŸ
A form with many controlsText boxes, number box, combo box, check box, list box and validation.
๐ŸชŸ
More input controlsDate picker, track bar, radio buttons, tool tips and the error marker.
๐ŸชŸ
The keyboard in a formKeyPress filters, Enter and Escape buttons, tab order, access keys and test keys.
๐ŸชŸ
Layout and richer controlsSplit bars, tabs, table layout, and a data grid with a filter.
๐ŸชŸ
A list with columnsListView details: columns, check boxes, sorting by a header, removing checked rows.
๐ŸชŸ
Editing a gridDataGridView with text, check box and combo box columns, cell events and totals.
๐ŸชŸ
A small text editorMenus, a status bar, open and save, dock layout.
๐ŸชŸ
Formatted textRichTextBox: bold and colored words, find and mark, save and load RTF.
๐ŸชŸ
The clipboardText, a table for a spreadsheet, a picture, and leaving the clipboard as it was.
๐ŸชŸ
Drag and dropDoDragDrop, AllowDrop and DragDrop, move or copy with Ctrl, dropped files, and a test without a mouse.
๐ŸชŸ
Your own dialogA modal form that asks for data, validates it and returns it; tested with a timer.
๐ŸชŸ
Closing a windowFormClosing and Cancel: ask to save changes, and a question that a test can answer.
๐ŸชŸ
More than one windowShow with an owner, one copy of a tool window, talking windows and OpenForms.
๐ŸชŸ
A tray iconNotifyIcon with a menu, hiding the window to the tray, and a balloon message.
๐ŸชŸ
Menus, toolbars, shortcutsWrite each action once and reach it from a menu, a toolbar, a context menu and a key.
๐ŸชŸ
Timers and progressA stopwatch, a progress bar, and a long job in small steps.
๐ŸชŸ
Drawing and animationA canvas, a timer and the keyboard: a bouncing ball and a paddle.
๐ŸชŸ
Drawing with the mouseMouseDown, MouseMove and MouseUp: a paint program with colors, pen sizes and a test.
๐ŸชŸ
ImagesDraw, read and change pixels, make a gray copy, resize and save PNG files.
๐ŸชŸ
Screens and pictures of windowsScreen, CopyFromScreen, DrawToBitmap, and checking a window by its pixels.
๐ŸชŸ
PrintingPrintDocument and PrintPage: a report on several pages, margins, landscape and a preview without a printer.
๐ŸชŸ
A chartScaling values to pixels, a round axis, bars, labels, saving, testing pixels.
๐ŸชŸ
A folder browserTreeView, ListView, recursion and the Tag property: a small Explorer.

WPF#

XAML windows, layout and styles, data binding, menus and tabs, lists and dynamic content, and animation (Windows only).

Projects with windows#

Complete programs: a to-do list, Tic-Tac-Toe, a quiz, a command runner, an address book with a database, a sorting lab, a maze, an image filter lab and a chat (Windows only).

Libraries and packages#

Giving Ring code to .NET (callbacks and events), exploring code with reflection and building it with expression trees, an object inspector, a library written in C#, and the generic functions; then NuGet packages and native code: how a package comes to Ring, a QR code, Excel files, pictures, PDF files, text to speech, sound, native DLLs, and a project that uses three packages together.

๐Ÿ“ฆ
Callbacks and eventsGive Ring code to .NET: function names, code texts, events, errors and the thread rule.
๐Ÿ“ฆ
Exploring .NET with reflectionAsk a class what it can do: properties, methods, parameters, enums.
๐Ÿ“ฆ
Project: an object inspectorGetType, GetProperties and GetValue: the properties of any object in a list.
๐Ÿ“ฆ
Expression treesCode as data: build, print, compile and call functions at run time.
๐Ÿ“ฆ
A library written in C#Build a small C# library, wrap it and call it from Ring.
๐Ÿ“ฆ
The generic functionsdnNewGeneric, dnType, dnNew with names, dnStatic, callMethod and getProp: what to use when there is no class.
๐Ÿ“ฆ
A NuGet packageFrom nuget.org to a Ring program: a project file, dotnet publish, the generator, and what to check when a package does not work.
๐Ÿ“ฆ
A QR codeA second NuGet package: QRCoder makes a code, printed as text and written as a PNG; error-correction levels and parameters by name.
๐Ÿ“ฆ
Excel filesClosedXML from nuget.org: write a sheet with formulas and a bold header, read it back, and use a package that works with interfaces.
๐Ÿ“ฆ
Pictures on every systemSkiaSharp: draw a circle and text, read pixels, save and read PNG on Windows and Linux; a package with a native library.
๐Ÿ“ฆ
PDF filesPDFsharp from nuget.org: pages in points, text, lines and fonts, and reading the file back to check it.
๐Ÿ“ฆ
Text to speechSystem.Speech: the voices of Windows, speech written to a WAV file for a silent test, the rate, and a package with a DLL for each system.
๐Ÿ“ฆ
SoundA WAV file made from numbers, played with SoundPlayer; wrapping a framework class that has no Ring class.
๐Ÿ“ฆ
Native DLLsP/Invoke: a few lines of C# give a function of kernel32 or user32 to Ring; numbers, texts, buffers, structures and errors.
๐Ÿ“ฆ
A project: from CSV to ExcelThree packages in one program: CsvHelper reads, LiteDB stores and finds, ClosedXML writes an Excel report.

Testing and release#

The mistakes that everybody makes first and their messages, programs that run on more than one system, testing your programs, and giving a program to other people.

After the tutorials: the Core concepts page lists the naming rules, the Class reference lists every class, and the applications are bigger programs to read.

RingDotNet โ€” use .NET classes and methods from Ring programs. Screenshots and output on these pages come from the real samples.