Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/core/tutorials/with-visual-studio-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Enhance the application to prompt the user for their name and display it along w

1. Replace the contents of the `Main` method in *Program.cs*, which is the line that calls `Console.WriteLine`, with the following code:

:::code language="csharp" source="./snippets/with-visual-studio/csharp/Program.cs" id="Snippet1":::
:::code language="csharp" source="./snippets/with-visual-studio/csharp/Program.cs" id="1":::

This code displays "What is your name?" in the console window and waits until the user enters a string followed by the <kbd>Enter</kbd> key. It stores this string in a variable named `name`. It also retrieves the value of the <xref:System.DateTime.Now?displayProperty=nameWithType> property, which contains the current local time, and assigns it to a variable named `date`. Finally, it displays these values in the console window.

Expand Down
2 changes: 1 addition & 1 deletion docs/core/tutorials/with-visual-studio-mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Enhance the application to prompt the user for their name and display it along w

1. In *Program.cs*, replace the contents of the `Main` method, which is the line that calls `Console.WriteLine`, with the following code:

:::code language="csharp" source="./snippets/with-visual-studio/csharp/Program.cs" id="Snippet1":::
:::code language="csharp" source="./snippets/with-visual-studio/csharp/Program.cs" id="1":::

This code displays "What is your name?" in the console window and waits until the user enters a string followed by the <kbd>enter</kbd> key. It stores this string in a variable named `name`. It also retrieves the value of the <xref:System.DateTime.Now?displayProperty=nameWithType> property, which contains the current local time, and assigns it to a variable named `date`. Finally, it displays these values in the console window.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ string [] pages = await Task.WhenAll(
You can use the same exception-handling techniques we discussed in the previous void-returning scenario:

```csharp
Task [] asyncOps =
Task<string> [] asyncOps =
(from url in urls select DownloadStringAsync(url)).ToArray();
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Imports System.Threading.Tasks
Module Example
' <Snippet4>
<Extension()>
Public Function ReadAsync(strm As Stream,
buffer As Byte(), offset As Integer,
Public Function ReadAsync(strm As Stream,
buffer As Byte(), offset As Integer,
count As Integer) As Task(Of Integer)
If strm Is Nothing Then
Throw New ArgumentNullException("stream")
End If
Return Task(Of Integer).Factory.FromAsync(AddressOf strm.BeginRead,
AddressOf strm.EndRead, buffer,
If strm Is Nothing Then
Throw New ArgumentNullException("stream")
End If

Return Task(Of Integer).Factory.FromAsync(AddressOf strm.BeginRead,
AddressOf strm.EndRead, buffer,
offset, count, Nothing)
End Function
' </Snippet4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Module Example
Public Function ReadAsync(stream As Stream, buffer As Byte(), _
offset As Integer, count As Integer) _
As Task(Of Integer)
If stream Is Nothing Then
Throw New ArgumentNullException("stream")
End If
If stream Is Nothing Then
Throw New ArgumentNullException("stream")
End If

Dim tcs As New TaskCompletionSource(Of Integer)()
stream.BeginRead(buffer, offset, count,
Sub(iar)
Try
tcs.TrySetResult(stream.EndRead(iar))
Catch e As OperationCanceledException
tcs.TrySetCanceled()
Catch e As Exception
tcs.TrySetException(e)
End Try
End Sub, Nothing)
Return tcs.Task
End Function
' </Snippet5>
Dim tcs As New TaskCompletionSource(Of Integer)()
stream.BeginRead(buffer, offset, count,
Sub(iar)
Try
tcs.TrySetResult(stream.EndRead(iar))
Catch e As OperationCanceledException
tcs.TrySetCanceled()
Catch e As Exception
tcs.TrySetException(e)
End Try
End Sub, Nothing)
Return tcs.Task
End Function
' </Snippet5>
End Module

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Public Class Win32
ByVal caption As String, ByVal Typ As Integer) As IntPtr
End Class

Public Class HelloWorld
Public Class HelloWorld
Public Shared Sub Main()
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0)
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,80 @@ Imports System.Text

<Assembly: CLSCompliant(True)>
Module Example
Public Sub Main()
InstantiateStringBuilder()
InstantiateWithCapacity()
Appending()
AppendingFormat()
Inserting()
Removing()
Replacing()
End Sub

Private Sub InstantiateStringBuilder()
' <Snippet1>
Dim myStringBuilder As New StringBuilder("Hello World!")
' </Snippet1>
End Sub

Private Sub InstantiateWithCapacity()
' <Snippet2>
Dim myStringBuilder As New StringBuilder("Hello World!", 25)
' </Snippet2>
' <Snippet3>
myStringBuilder.Capacity = 25
' </Snippet3>
End Sub

Private Sub Appending()
' <Snippet4>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Append(" What a beautiful day.")
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello World! What a beautiful day.
' </Snippet4>
End Sub
Public Sub Main()
InstantiateStringBuilder()
InstantiateWithCapacity()
Appending()
AppendingFormat()
Inserting()
Removing()
Replacing()
End Sub

Private Sub AppendingFormat()
' <Snippet5>
Dim MyInt As Integer = 25
Dim myStringBuilder As New StringBuilder("Your total is ")
myStringBuilder.AppendFormat("{0:C} ", MyInt)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Your total is $25.00
' </Snippet5>
End Sub
Private Sub InstantiateStringBuilder()
' <Snippet1>
Dim myStringBuilder As New StringBuilder("Hello World!")
' </Snippet1>
End Sub

Private Sub Inserting()
' <Snippet6>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Insert(6, "Beautiful ")
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello Beautiful World!
' </Snippet6>
End Sub
Private Sub InstantiateWithCapacity()
' <Snippet2>
Dim myStringBuilder As New StringBuilder("Hello World!", 25)
' </Snippet2>
' <Snippet3>
myStringBuilder.Capacity = 25
' </Snippet3>
End Sub

Private Sub Removing()
' <Snippet7>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Remove(5, 7)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello
' </Snippet7>
End Sub

Private Sub Replacing()
' <Snippet8>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Replace("!"c, "?"c)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello World?
' </Snippet8>
End Sub
Private Sub Appending()
' <Snippet4>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Append(" What a beautiful day.")
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello World! What a beautiful day.
' </Snippet4>
End Sub

Private Sub AppendingFormat()
' <Snippet5>
Dim MyInt As Integer = 25
Dim myStringBuilder As New StringBuilder("Your total is ")
myStringBuilder.AppendFormat("{0:C} ", MyInt)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Your total is $25.00
' </Snippet5>
End Sub

Private Sub Inserting()
' <Snippet6>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Insert(6, "Beautiful ")
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello Beautiful World!
' </Snippet6>
End Sub

Private Sub Removing()
' <Snippet7>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Remove(5, 7)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello
' </Snippet7>
End Sub

Private Sub Replacing()
' <Snippet8>
Dim myStringBuilder As New StringBuilder("Hello World!")
myStringBuilder.Replace("!"c, "?"c)
Console.WriteLine(myStringBuilder)
' The example displays the following output:
' Hello World?
' </Snippet8>
End Sub
End Module

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Imports System.Text
Public Class CharsToStr
Public Shared Sub Main()
Dim sb As New StringBuilder("Start with a string and add from ")
Dim b() As Char = { "c", "h", "a", "r", ".", " ", "B", "u", "t", " ", "n", "o", "t", " ", "a", "l", "l" }
Dim b() As Char = {"c", "h", "a", "r", ".", " ", "B", "u", "t", " ", "n", "o", "t", " ", "a", "l", "l"}

Using sw As StringWriter = New StringWriter(sb)
' Write five characters from the array into the StringBuilder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ Option Strict On
Imports System.Text

Module Example
Public Sub Main()
Dim sb As New StringBuilder()
Dim flag As Boolean = True
Dim spellings() As String = { "recieve", "receeve", "receive" }
sb.AppendFormat("Which of the following spellings is {0}:", flag)
sb.AppendLine()
For ctr As Integer = 0 To spellings.GetUpperBound(0)
sb.AppendFormat(" {0}. {1}", ctr, spellings(ctr))
sb.AppendLine()
Next
sb.AppendLine()
Console.WriteLine(sb.ToString())
End Sub
Public Sub Main()
Dim sb As New StringBuilder()
Dim flag As Boolean = True
Dim spellings() As String = {"recieve", "receeve", "receive"}
sb.AppendFormat("Which of the following spellings is {0}:", flag)
sb.AppendLine()
For ctr As Integer = 0 To spellings.GetUpperBound(0)
sb.AppendFormat(" {0}. {1}", ctr, spellings(ctr))
sb.AppendLine()
Next
sb.AppendLine()
Console.WriteLine(sb.ToString())
End Sub
End Module
' The example displays the following output:
' Which of the following spellings is True:
' 0. recieve
' 1. receeve
' 2. receive
' </Snippet10>
' </Snippet10>
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ Option Strict On
Imports System.Threading

Module Example
Public Sub Main()
' Interrupt a sleeping thread.
Dim sleepingThread = New Thread(AddressOf Example.SleepIndefinitely)
sleepingThread.Name = "Sleeping"
sleepingThread.Start()
Thread.Sleep(2000)
sleepingThread.Interrupt()

Thread.Sleep(1000)

sleepingThread = New Thread(AddressOf Example.SleepIndefinitely)
sleepingThread.Name = "Sleeping2"
sleepingThread.Start()
Thread.Sleep(2000)
sleepingThread.Abort()
End Sub
Public Sub Main()
' Interrupt a sleeping thread.
Dim sleepingThread = New Thread(AddressOf Example.SleepIndefinitely)
sleepingThread.Name = "Sleeping"
sleepingThread.Start()
Thread.Sleep(2000)
sleepingThread.Interrupt()

Private Sub SleepIndefinitely()
Console.WriteLine("Thread '{0}' about to sleep indefinitely.",
Thread.CurrentThread.Name)
Try
Thread.Sleep(Timeout.Infinite)
Catch ex As ThreadInterruptedException
Console.WriteLine("Thread '{0}' awoken.",
Thread.CurrentThread.Name)
Catch ex As ThreadAbortException
Console.WriteLine("Thread '{0}' aborted.",
Thread.CurrentThread.Name)
Finally
Console.WriteLine("Thread '{0}' executing finally block.",
Thread.CurrentThread.Name)
End Try
Console.WriteLine("Thread '{0} finishing normal execution.",
Thread.CurrentThread.Name)
Console.WriteLine()
End Sub
Thread.Sleep(1000)

sleepingThread = New Thread(AddressOf Example.SleepIndefinitely)
sleepingThread.Name = "Sleeping2"
sleepingThread.Start()
Thread.Sleep(2000)
sleepingThread.Abort()
End Sub

Private Sub SleepIndefinitely()
Console.WriteLine("Thread '{0}' about to sleep indefinitely.",
Thread.CurrentThread.Name)
Try
Thread.Sleep(Timeout.Infinite)
Catch ex As ThreadInterruptedException
Console.WriteLine("Thread '{0}' awoken.",
Thread.CurrentThread.Name)
Catch ex As ThreadAbortException
Console.WriteLine("Thread '{0}' aborted.",
Thread.CurrentThread.Name)
Finally
Console.WriteLine("Thread '{0}' executing finally block.",
Thread.CurrentThread.Name)
End Try
Console.WriteLine("Thread '{0} finishing normal execution.",
Thread.CurrentThread.Name)
Console.WriteLine()
End Sub
End Module
' The example displays the following output:
' Thread 'Sleeping' about to sleep indefinitely.
Expand Down
Loading