Skip to content

Add new F# Console snippet references #3664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions xml/System/Console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@

[!code-csharp[System.Console.Class#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.console.class/cs/unicode1.cs#1)]
[!code-vb[System.Console.Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.console.class/vb/unicode1.vb#1)]
[!code-fsharp[System.Console.Class#1](~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.console.class/fs/unicode1.fs#1)]

In addition to supporting code pages, the <xref:System.Console> class supports UTF-8 encoding with the <xref:System.Text.UTF8Encoding> class. Beginning with the .NET Framework 4.5, the <xref:System.Console> class also supports UTF-16 encoding with the <xref:System.Text.UnicodeEncoding> class. To display Unicode characters to the console. you set the <xref:System.Console.OutputEncoding%2A> property to either <xref:System.Text.UTF8Encoding> or <xref:System.Text.UnicodeEncoding>.

Support for Unicode characters requires the encoder to recognize a particular Unicode character, and also requires a font that has the glyphs needed to render that character. To successfully display Unicode characters to the console, the console font must be set to a non-raster or TrueType font such as Consolas or Lucida Console. The following example shows how you can programmatically change the font from a raster font to Lucida Console.

[!code-csharp[System.Console.Class.Unsafe#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.console.class.unsafe/cs/setfont1.cs#3)]
[!code-vb[System.Console.Class.Unsafe#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.console.class.unsafe/vb/setfont1.vb#3)]
[!code-fsharp[System.Console.Class.Unsafe#3](~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.console.class.unsafe/fs/setfont1.fs#3)]

However, TrueType fonts can display only a subset of glyphs. For example, the Lucida Console font displays only 643 of the approximately 64,000 available characters from U+0021 to U+FB02. To see which characters a particular font supports, open the **Fonts** applet in Control Panel, choose the **Find a character** option, and choose the font whose character set you'd like to examine in the **Font** list of the **Character Map** window.

Windows uses font linking to display glyphs that are not available in a particular font. For information about font linking to display additional character sets, see [Globalization Step-by-Step: Fonts](https://go.microsoft.com/fwlink/?LinkId=229111). Linked fonts are defined in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink subkey of the registry. Each entry associated with this subkey corresponds to the name of a base font, and its value is a string array that defines the font files and the fonts that are linked to the base font. Each member of the array defines a linked font and takes the form *font-file-name*,*font-name*. The following example illustrates how you can programmatically define a linked font named SimSun found in a font file named simsun.ttc that displays Simplified Han characters.

[!code-csharp[System.Console.Class#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.console.class/cs/fontlink1.cs#2)]
[!code-vb[System.Console.Class#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.console.class/vb/fontlink1.vb#2)]
[!code-fsharp[System.Console.Class#2](~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.console.class/fs/fontlink1.fs#2)]

Unicode support for the console has the following limitations:

Expand All @@ -113,6 +116,7 @@

[!code-csharp[System.Console.Class#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.console.class/cs/normalize1.cs#5)]
[!code-vb[System.Console.Class#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.console.class/vb/normalize1.vb#5)]
[!code-fsharp[System.Console.Class#5](~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.console.class/fs/normalize1.fs#5)]

Note that normalization is a viable solution only if the Unicode standard for the character includes a pre-composed form that corresponds to a particular combining character sequence.

Expand All @@ -122,6 +126,7 @@

[!code-csharp[System.Console.Class#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.console.class/cs/example3.cs#4)]
[!code-vb[System.Console.Class#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.console.class/vb/example3.vb#4)]
[!code-fsharp[System.Console.Class#4](~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.console.class/fs/example3.fs#4)]

<a name="Operations"></a>
## Common Operations
Expand Down Expand Up @@ -175,6 +180,7 @@
[!code-cpp[Classic Console Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic Console Example/CPP/source.cpp#1)]
[!code-csharp[Classic Console Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic Console Example/CS/source.cs#1)]
[!code-vb[Classic Console Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Console Example/VB/source.vb#1)]
[!code-fsharp[Classic Console Example#1](~/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic Console Example/FS/source.fs#1)]

]]></format>
</remarks>
Expand Down