Skip to content

Commit debae25

Browse files
authored
Convert to interpolated strings (VS_Snippets_CLR directory) (#45433)
1 parent 75412af commit debae25

File tree

155 files changed

+848
-982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+848
-982
lines changed

docs/standard/base-types/custom-date-and-time-format-strings.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ title: "Custom date and time format strings"
33
description: Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates & times.
44
ms.date: 05/12/2022
55
ms.topic: reference
6-
dev_langs:
6+
dev_langs:
77
- "csharp"
88
- "vb"
9-
helpviewer_keywords:
9+
helpviewer_keywords:
1010
- "formatting [.NET], dates"
1111
- "custom DateTime format string"
1212
- "format specifiers, custom date and time"
@@ -715,9 +715,9 @@ The following example includes the literal characters "pst" (for Pacific Standar
715715

716716
A custom date and time format string consists of two or more characters. Date and time formatting methods interpret any single-character string as a standard date and time format string. If they don't recognize the character as a valid format specifier, they throw a <xref:System.FormatException>. For example, a format string that consists only of the specifier "h" is interpreted as a standard date and time format string. However, in this particular case, an exception is thrown because there is no "h" standard date and time format specifier.
717717

718-
To use any of the custom date and time format specifiers as the only specifier in a format string (that is, to use the "d", "f", "F", "g", "h", "H", "K", "m", "M", "s", "t", "y", "z", ":", or "/" custom format specifier by itself), include a space before or after the specifier, or include a percent ("%") format specifier before the single custom date and time specifier.
718+
To use any of the custom date and time format specifiers as the only specifier in a format string (that is, to use the "d", "f", "F", "g", "h", "H", "K", "m", "M", "s", "t", "y", "z", ":", or "/" custom format specifier by itself), include a space before the specifier, or include a percent ("%") format specifier before the single custom date and time specifier.
719719

720-
For example, "`%h"` is interpreted as a custom date and time format string that displays the hour represented by the current date and time value. You can also use the " h" or "h " format string, although this includes a space in the result string along with the hour. The following example illustrates these three format strings.
720+
For example, "`%h"` is interpreted as a custom date and time format string that displays the hour represented by the current date and time value. You can also use the " h" format string, although this includes a space in the result string along with the hour. The following example illustrates these format strings.
721721

722722
[!code-csharp-interactive[Formatting.DateAndTime.Custom#16](~/samples/snippets/csharp/VS_Snippets_CLR/Formatting.DateAndTime.Custom/cs/literal1.cs#16)]
723723
[!code-vb[Formatting.DateAndTime.Custom#16](~/samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.DateAndTime.Custom/vb/literal1.vb#16)]

samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/EndInvoke.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Examples.AdvancedProgramming.AsynchronousOperations
66
{
7-
public class AsyncMain
7+
public class AsyncMain3
88
{
99
public static void Main()
1010
{
@@ -22,8 +22,7 @@ public static void Main()
2222
out threadId, null, null);
2323

2424
Thread.Sleep(0);
25-
Console.WriteLine("Main thread {0} does some work.",
26-
Thread.CurrentThread.ManagedThreadId);
25+
Console.WriteLine($"Main thread {Thread.CurrentThread.ManagedThreadId} does some work.");
2726

2827
// Call EndInvoke to wait for the asynchronous call to complete,
2928
// and to retrieve the results.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net481</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/callback.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Examples.AdvancedProgramming.AsynchronousOperations
77
{
8-
public class AsyncMain
8+
public class AsyncMain4
99
{
1010
static void Main()
1111
{
@@ -34,8 +34,7 @@ static void Main()
3434
new AsyncCallback(CallbackMethod),
3535
"The call executed on thread {0}, with return value \"{1}\".");
3636

37-
Console.WriteLine("The main thread {0} continues to execute...",
38-
Thread.CurrentThread.ManagedThreadId);
37+
Console.WriteLine($"The main thread {Thread.CurrentThread.ManagedThreadId} continues to execute...");
3938

4039
// The callback is made on a ThreadPool thread. ThreadPool threads
4140
// are background threads, which do not keep the application running

samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/makefile

Lines changed: 0 additions & 21 deletions
This file was deleted.

samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/waithandle.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Examples.AdvancedProgramming.AsynchronousOperations
66
{
7-
public class AsyncMain
7+
public class AsyncMain2
88
{
99
static void Main()
1010
{
@@ -22,8 +22,7 @@ static void Main()
2222
out threadId, null, null);
2323

2424
Thread.Sleep(0);
25-
Console.WriteLine("Main thread {0} does some work.",
26-
Thread.CurrentThread.ManagedThreadId);
25+
Console.WriteLine($"Main thread {Thread.CurrentThread.ManagedThreadId} does some work.");
2726

2827
// Wait for the WaitHandle to become signaled.
2928
result.AsyncWaitHandle.WaitOne();

samples/snippets/csharp/VS_Snippets_CLR/AsyncDesignPattern/CS/AsyncDelegateNoStateObject.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet4>
1+
// <Snippet4>
22
/*
33
The following example demonstrates using asynchronous methods to
44
get Domain Name System information for the specified host computers.
@@ -24,7 +24,7 @@ static void UpdateUserInterface()
2424
{
2525
// Print a message to indicate that the application
2626
// is still working on the remaining requests.
27-
Console.WriteLine("{0} requests remaining.", requestCounter);
27+
Console.WriteLine($"{requestCounter} requests remaining.");
2828
}
2929
public static void Main()
3030
{
@@ -58,8 +58,7 @@ public static void Main()
5858
// A SocketException was thrown.
5959
if (message != null)
6060
{
61-
Console.WriteLine("Request for {0} returned message: {1}",
62-
hostNames[i], message);
61+
Console.WriteLine($"Request for {hostNames[i]} returned message: {message}");
6362
continue;
6463
}
6564
// Get the results.
@@ -68,15 +67,15 @@ public static void Main()
6867
IPAddress[] addresses = h.AddressList;
6968
if (aliases.Length > 0)
7069
{
71-
Console.WriteLine("Aliases for {0}", hostNames[i]);
70+
Console.WriteLine($"Aliases for {hostNames[i]}");
7271
for (int j = 0; j < aliases.Length; j++)
7372
{
74-
Console.WriteLine("{0}", aliases[j]);
73+
Console.WriteLine($"{aliases[j]}");
7574
}
7675
}
7776
if (addresses.Length > 0)
7877
{
79-
Console.WriteLine("Addresses for {0}", hostNames[i]);
78+
Console.WriteLine($"Addresses for {hostNames[i]}");
8079
for (int k = 0; k < addresses.Length; k++)
8180
{
8281
Console.WriteLine("{0}",addresses[k].ToString());

samples/snippets/csharp/VS_Snippets_CLR/AsyncDesignPattern/CS/AsyncDelegateWithStateObject.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet5>
1+
// <Snippet5>
22
/*
33
The following example demonstrates using asynchronous methods to
44
get Domain Name System information for the specified host computer.
@@ -70,7 +70,7 @@ static void UpdateUserInterface()
7070
{
7171
// Print a message to indicate that the application
7272
// is still working on the remaining requests.
73-
Console.WriteLine("{0} requests remaining.", requestCounter);
73+
Console.WriteLine($"{requestCounter} requests remaining.");
7474
}
7575
public static void Main()
7676
{
@@ -104,8 +104,7 @@ public static void Main()
104104
{
105105
if (r.ExceptionObject != null)
106106
{
107-
Console.WriteLine("Request for host {0} returned the following error: {1}.",
108-
r.HostName, r.ExceptionObject.Message);
107+
Console.WriteLine($"Request for host {r.HostName} returned the following error: {r.ExceptionObject.Message}.");
109108
}
110109
else
111110
{
@@ -115,15 +114,15 @@ public static void Main()
115114
IPAddress[] addresses = h.AddressList;
116115
if (aliases.Length > 0)
117116
{
118-
Console.WriteLine("Aliases for {0}", r.HostName);
117+
Console.WriteLine($"Aliases for {r.HostName}");
119118
for (int j = 0; j < aliases.Length; j++)
120119
{
121-
Console.WriteLine("{0}", aliases[j]);
120+
Console.WriteLine($"{aliases[j]}");
122121
}
123122
}
124123
if (addresses.Length > 0)
125124
{
126-
Console.WriteLine("Addresses for {0}", r.HostName);
125+
Console.WriteLine($"Addresses for {r.HostName}");
127126
for (int k = 0; k < addresses.Length; k++)
128127
{
129128
Console.WriteLine("{0}",addresses[k].ToString());

samples/snippets/csharp/VS_Snippets_CLR/AsyncDesignPattern/CS/Async_EndBlock.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AsynchSampler
1+
// AsynchSampler
22
//<Snippet1>
33
/*
44
The following example demonstrates using asynchronous methods to
@@ -39,7 +39,7 @@ public static void Main(string[] args)
3939
Console.WriteLine("Aliases");
4040
for (int i = 0; i < aliases.Length; i++)
4141
{
42-
Console.WriteLine("{0}", aliases[i]);
42+
Console.WriteLine($"{aliases[i]}");
4343
}
4444
}
4545
if (addresses.Length > 0)
@@ -53,7 +53,7 @@ public static void Main(string[] args)
5353
}
5454
catch (SocketException e)
5555
{
56-
Console.WriteLine("An exception occurred while processing the request: {0}", e.Message);
56+
Console.WriteLine($"An exception occurred while processing the request: {e.Message}");
5757
}
5858
}
5959
}

samples/snippets/csharp/VS_Snippets_CLR/AsyncDesignPattern/CS/Async_EndBlockWait.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet2>
1+
// <Snippet2>
22
/*
33
The following example demonstrates using asynchronous methods to
44
get Domain Name System information for the specified host computer.
@@ -40,7 +40,7 @@ public static void Main(string[] args)
4040
Console.WriteLine("Aliases");
4141
for (int i = 0; i < aliases.Length; i++)
4242
{
43-
Console.WriteLine("{0}", aliases[i]);
43+
Console.WriteLine($"{aliases[i]}");
4444
}
4545
}
4646
if (addresses.Length > 0)
@@ -54,8 +54,7 @@ public static void Main(string[] args)
5454
}
5555
catch (SocketException e)
5656
{
57-
Console.WriteLine("Exception occurred while processing the request: {0}",
58-
e.Message);
57+
Console.WriteLine($"Exception occurred while processing the request: {e.Message}");
5958
}
6059
}
6160
}

0 commit comments

Comments
 (0)