Skip to content

Commit 4fe248d

Browse files
authored
Convert to interpolated strings (Misc, VBCSharp, Remoting, CLR_System) (#45434)
1 parent c284277 commit 4fe248d

File tree

90 files changed

+1059
-1551
lines changed

Some content is hidden

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

90 files changed

+1059
-1551
lines changed

samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Conceptual.Conversions/cs/Conversions.cs

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
public class Class1
44
{
@@ -44,30 +44,21 @@ private static void ConvertUsingDateTime()
4444
// Convert UTC to DateTime value
4545
sourceTime = new DateTimeOffset(baseTime, TimeSpan.Zero);
4646
targetTime = sourceTime.DateTime;
47-
Console.WriteLine("{0} converts to {1} {2}",
48-
sourceTime,
49-
targetTime,
50-
targetTime.Kind);
47+
Console.WriteLine($"{sourceTime} converts to {targetTime} {targetTime.Kind}");
5148

5249
// Convert local time to DateTime value
5350
sourceTime = new DateTimeOffset(baseTime,
5451
TimeZoneInfo.Local.GetUtcOffset(baseTime));
5552
targetTime = sourceTime.DateTime;
56-
Console.WriteLine("{0} converts to {1} {2}",
57-
sourceTime,
58-
targetTime,
59-
targetTime.Kind);
53+
Console.WriteLine($"{sourceTime} converts to {targetTime} {targetTime.Kind}");
6054

6155
// Convert Central Standard Time to a DateTime value
6256
try
6357
{
6458
TimeSpan offset = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").GetUtcOffset(baseTime);
6559
sourceTime = new DateTimeOffset(baseTime, offset);
6660
targetTime = sourceTime.DateTime;
67-
Console.WriteLine("{0} converts to {1} {2}",
68-
sourceTime,
69-
targetTime,
70-
targetTime.Kind);
61+
Console.WriteLine($"{sourceTime} converts to {targetTime} {targetTime.Kind}");
7162
}
7263
catch (TimeZoneNotFoundException)
7364
{
@@ -85,10 +76,7 @@ private static void ConvertUtcTime()
8576
// <Snippet6>
8677
DateTimeOffset utcTime1 = new DateTimeOffset(2008, 6, 19, 7, 0, 0, TimeSpan.Zero);
8778
DateTime utcTime2 = utcTime1.UtcDateTime;
88-
Console.WriteLine("{0} converted to {1} {2}",
89-
utcTime1,
90-
utcTime2,
91-
utcTime2.Kind);
79+
Console.WriteLine($"{utcTime1} converted to {utcTime2} {utcTime2.Kind}");
9280
// The example displays the following output to the console:
9381
// 6/19/2008 7:00:00 AM +00:00 converted to 6/19/2008 7:00:00 AM Utc
9482
// </Snippet6>
@@ -104,10 +92,7 @@ private static void ConvertLocalTime()
10492
if (utcTime1.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(utcTime1.DateTime)))
10593
utcTime2 = DateTime.SpecifyKind(utcTime2, DateTimeKind.Local);
10694

107-
Console.WriteLine("{0} converted to {1} {2}",
108-
utcTime1,
109-
utcTime2,
110-
utcTime2.Kind);
95+
Console.WriteLine($"{utcTime1} converted to {utcTime2} {utcTime2.Kind}");
11196
// The example displays the following output to the console:
11297
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
11398
// </Snippet7>
@@ -134,28 +119,19 @@ private static void CallConversionFunction()
134119
// Convert UTC time
135120
DateTimeOffset utcTime = new DateTimeOffset(timeComponent, TimeSpan.Zero);
136121
returnedDate = ConvertFromDateTimeOffset(utcTime);
137-
Console.WriteLine("{0} converted to {1} {2}",
138-
utcTime,
139-
returnedDate,
140-
returnedDate.Kind);
122+
Console.WriteLine($"{utcTime} converted to {returnedDate} {returnedDate.Kind}");
141123

142124
// Convert local time
143125
DateTimeOffset localTime = new DateTimeOffset(timeComponent,
144126
TimeZoneInfo.Local.GetUtcOffset(timeComponent));
145127
returnedDate = ConvertFromDateTimeOffset(localTime);
146-
Console.WriteLine("{0} converted to {1} {2}",
147-
localTime,
148-
returnedDate,
149-
returnedDate.Kind);
128+
Console.WriteLine($"{localTime} converted to {returnedDate} {returnedDate.Kind}");
150129

151130
// Convert Central Standard Time
152131
DateTimeOffset cstTime = new DateTimeOffset(timeComponent,
153132
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").GetUtcOffset(timeComponent));
154133
returnedDate = ConvertFromDateTimeOffset(cstTime);
155-
Console.WriteLine("{0} converted to {1} {2}",
156-
cstTime,
157-
returnedDate,
158-
returnedDate.Kind);
134+
Console.WriteLine($"{cstTime} converted to {returnedDate} {returnedDate.Kind}");
159135
// The example displays the following output to the console:
160136
// 6/19/2008 7:00:00 AM +00:00 converted to 6/19/2008 7:00:00 AM Utc
161137
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
@@ -169,10 +145,7 @@ private static void ConvertUtcToDateTimeOffset()
169145
DateTime utcTime1 = new DateTime(2008, 6, 19, 7, 0, 0);
170146
utcTime1 = DateTime.SpecifyKind(utcTime1, DateTimeKind.Utc);
171147
DateTimeOffset utcTime2 = utcTime1;
172-
Console.WriteLine("Converted {0} {1} to a DateTimeOffset value of {2}",
173-
utcTime1,
174-
utcTime1.Kind,
175-
utcTime2);
148+
Console.WriteLine($"Converted {utcTime1} {utcTime1.Kind} to a DateTimeOffset value of {utcTime2}");
176149
// This example displays the following output to the console:
177150
// Converted 6/19/2008 7:00:00 AM Utc to a DateTimeOffset value of 6/19/2008 7:00:00 AM +00:00
178151
// </Snippet1>
@@ -184,10 +157,7 @@ private static void ConvertLocalToDateTimeOffset()
184157
DateTime localTime1 = new DateTime(2008, 6, 19, 7, 0, 0);
185158
localTime1 = DateTime.SpecifyKind(localTime1, DateTimeKind.Local);
186159
DateTimeOffset localTime2 = localTime1;
187-
Console.WriteLine("Converted {0} {1} to a DateTimeOffset value of {2}",
188-
localTime1,
189-
localTime1.Kind,
190-
localTime2);
160+
Console.WriteLine($"Converted {localTime1} {localTime1.Kind} to a DateTimeOffset value of {localTime2}");
191161
// This example displays the following output to the console:
192162
// Converted 6/19/2008 7:00:00 AM Local to a DateTimeOffset value of 6/19/2008 7:00:00 AM -07:00
193163
// </Snippet2>
@@ -198,10 +168,7 @@ private static void ConvertUnspecifiedToDateTimeOffset1()
198168
// <Snippet3>
199169
DateTime time1 = new DateTime(2008, 6, 19, 7, 0, 0); // Kind is DateTimeKind.Unspecified
200170
DateTimeOffset time2 = time1;
201-
Console.WriteLine("Converted {0} {1} to a DateTimeOffset value of {2}",
202-
time1,
203-
time1.Kind,
204-
time2);
171+
Console.WriteLine($"Converted {time1} {time1.Kind} to a DateTimeOffset value of {time2}");
205172
// This example displays the following output to the console:
206173
// Converted 6/19/2008 7:00:00 AM Unspecified to a DateTimeOffset value of 6/19/2008 7:00:00 AM -07:00
207174
// </Snippet3>
@@ -215,10 +182,7 @@ private static void ConvertUnspecifiedToDateTimeOffset2()
215182
{
216183
DateTimeOffset time2 = new DateTimeOffset(time1,
217184
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").GetUtcOffset(time1));
218-
Console.WriteLine("Converted {0} {1} to a DateTime value of {2}",
219-
time1,
220-
time1.Kind,
221-
time2);
185+
Console.WriteLine($"Converted {time1} {time1.Kind} to a DateTime value of {time2}");
222186
}
223187
// Handle exception if time zone is not defined in registry
224188
catch (TimeZoneNotFoundException)
@@ -238,10 +202,7 @@ private static void ConvertUsingLocalTimeProperty1()
238202
TimeZoneInfo.Local.GetUtcOffset(sourceDate));
239203
DateTime localTime2 = localTime1.LocalDateTime;
240204

241-
Console.WriteLine("{0} converted to {1} {2}",
242-
localTime1,
243-
localTime2,
244-
localTime2.Kind);
205+
Console.WriteLine($"{localTime1} converted to {localTime2} {localTime2.Kind}");
245206
// The example displays the following output to the console:
246207
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
247208
// </Snippet10>
@@ -257,19 +218,13 @@ private static void ConvertUsingLocalTimeProperty2()
257218
originalDate = new DateTimeOffset(2008, 6, 18, 7, 0, 0,
258219
new TimeSpan(-5, 0, 0));
259220
localDate = originalDate.LocalDateTime;
260-
Console.WriteLine("{0} converted to {1} {2}",
261-
originalDate,
262-
localDate,
263-
localDate.Kind);
221+
Console.WriteLine($"{originalDate} converted to {localDate} {localDate.Kind}");
264222
// Convert time originating in a different time zone
265223
// so local time zone's adjustment rules are applied
266224
originalDate = new DateTimeOffset(2007, 11, 4, 4, 0, 0,
267225
new TimeSpan(-5, 0, 0));
268226
localDate = originalDate.LocalDateTime;
269-
Console.WriteLine("{0} converted to {1} {2}",
270-
originalDate,
271-
localDate,
272-
localDate.Kind);
227+
Console.WriteLine($"{originalDate} converted to {localDate} {localDate.Kind}");
273228
// The example displays the following output to the console,
274229
// when you run it on a machine that is set to Pacific Time (US & Canada):
275230
// 6/18/2008 7:00:00 AM -05:00 converted to 6/18/2008 5:00:00 AM Local
@@ -282,10 +237,7 @@ private static void PerformUtcAndTypeConversion()
282237
// <Snippet12>
283238
DateTimeOffset originalTime = new DateTimeOffset(2008, 6, 19, 7, 0, 0, new TimeSpan(5, 0, 0));
284239
DateTime utcTime = originalTime.UtcDateTime;
285-
Console.WriteLine("{0} converted to {1} {2}",
286-
originalTime,
287-
utcTime,
288-
utcTime.Kind);
240+
Console.WriteLine($"{originalTime} converted to {utcTime} {utcTime.Kind}");
289241
// The example displays the following output to the console:
290242
// 6/19/2008 7:00:00 AM +05:00 converted to 6/19/2008 2:00:00 AM Utc
291243
// </Snippet12>

samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Conceptual/cs/Conceptual1.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@
44

55
public class TimeOffsets
66
{
7-
public static void Main()
8-
{
9-
DateTime thisDate = new DateTime(2007, 3, 10, 0, 0, 0);
10-
DateTime dstDate = new DateTime(2007, 6, 10, 0, 0, 0);
11-
DateTimeOffset thisTime;
7+
public static void Main()
8+
{
9+
DateTime thisDate = new DateTime(2007, 3, 10, 0, 0, 0);
10+
DateTime dstDate = new DateTime(2007, 6, 10, 0, 0, 0);
11+
DateTimeOffset thisTime;
1212

13-
thisTime = new DateTimeOffset(dstDate, new TimeSpan(-7, 0, 0));
14-
ShowPossibleTimeZones(thisTime);
13+
thisTime = new DateTimeOffset(dstDate, new TimeSpan(-7, 0, 0));
14+
ShowPossibleTimeZones(thisTime);
1515

16-
thisTime = new DateTimeOffset(thisDate, new TimeSpan(-6, 0, 0));
17-
ShowPossibleTimeZones(thisTime);
16+
thisTime = new DateTimeOffset(thisDate, new TimeSpan(-6, 0, 0));
17+
ShowPossibleTimeZones(thisTime);
1818

19-
thisTime = new DateTimeOffset(thisDate, new TimeSpan(+1, 0, 0));
20-
ShowPossibleTimeZones(thisTime);
21-
}
19+
thisTime = new DateTimeOffset(thisDate, new TimeSpan(+1, 0, 0));
20+
ShowPossibleTimeZones(thisTime);
21+
}
2222

23-
private static void ShowPossibleTimeZones(DateTimeOffset offsetTime)
24-
{
25-
TimeSpan offset = offsetTime.Offset;
26-
ReadOnlyCollection<TimeZoneInfo> timeZones;
23+
private static void ShowPossibleTimeZones(DateTimeOffset offsetTime)
24+
{
25+
TimeSpan offset = offsetTime.Offset;
26+
ReadOnlyCollection<TimeZoneInfo> timeZones;
2727

28-
Console.WriteLine("{0} could belong to the following time zones:",
29-
offsetTime.ToString());
30-
// Get all time zones defined on local system
31-
timeZones = TimeZoneInfo.GetSystemTimeZones();
32-
// Iterate time zones
33-
foreach (TimeZoneInfo timeZone in timeZones)
34-
{
35-
// Compare offset with offset for that date in that time zone
36-
if (timeZone.GetUtcOffset(offsetTime.DateTime).Equals(offset))
37-
Console.WriteLine(" {0}", timeZone.DisplayName);
38-
}
39-
Console.WriteLine();
40-
}
28+
Console.WriteLine("{0} could belong to the following time zones:",
29+
offsetTime.ToString());
30+
// Get all time zones defined on local system
31+
timeZones = TimeZoneInfo.GetSystemTimeZones();
32+
// Iterate time zones
33+
foreach (TimeZoneInfo timeZone in timeZones)
34+
{
35+
// Compare offset with offset for that date in that time zone
36+
if (timeZone.GetUtcOffset(offsetTime.DateTime).Equals(offset))
37+
Console.WriteLine($" {timeZone.DisplayName}");
38+
}
39+
Console.WriteLine();
40+
}
4141
}
4242
// This example displays the following output to the console:
4343
// 6/10/2007 12:00:00 AM -07:00 could belong to the following time zones:

samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Conceptual/cs/Conceptual2.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// <Snippet2>
22
using System;
33

4-
public enum TimeComparison
4+
public enum TimeComparison2
55
{
6-
EarlierThan = -1,
7-
TheSameAs = 0,
8-
LaterThan = 1
6+
EarlierThan = -1,
7+
TheSameAs = 0,
8+
LaterThan = 1
99
}
1010

1111
public class DateManipulation
1212
{
13-
public static void Main()
14-
{
15-
DateTime localTime = DateTime.Now;
16-
DateTime utcTime = DateTime.UtcNow;
13+
public static void Main()
14+
{
15+
DateTime localTime = DateTime.Now;
16+
DateTime utcTime = DateTime.UtcNow;
1717

18-
Console.WriteLine("Difference between {0} and {1} time: {2}:{3} hours",
19-
localTime.Kind,
20-
utcTime.Kind,
21-
(localTime - utcTime).Hours,
22-
(localTime - utcTime).Minutes);
23-
Console.WriteLine("The {0} time is {1} the {2} time.",
24-
localTime.Kind,
25-
Enum.GetName(typeof(TimeComparison), localTime.CompareTo(utcTime)),
26-
utcTime.Kind);
27-
}
18+
Console.WriteLine("Difference between {0} and {1} time: {2}:{3} hours",
19+
localTime.Kind,
20+
utcTime.Kind,
21+
(localTime - utcTime).Hours,
22+
(localTime - utcTime).Minutes);
23+
Console.WriteLine("The {0} time is {1} the {2} time.",
24+
localTime.Kind,
25+
Enum.GetName(typeof(TimeComparison2), localTime.CompareTo(utcTime)),
26+
utcTime.Kind);
27+
}
2828
}
2929
// If run in the U.S. Pacific Standard Time zone, the example displays
3030
// the following output to the console:

samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Conceptual/cs/Conceptual3.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33

44
public enum TimeComparison
55
{
6-
EarlierThan = -1,
7-
TheSameAs = 0,
8-
LaterThan = 1
6+
EarlierThan = -1,
7+
TheSameAs = 0,
8+
LaterThan = 1
99
}
1010

1111
public class DateTimeOffsetManipulation
1212
{
13-
public static void Main()
14-
{
15-
DateTimeOffset localTime = DateTimeOffset.Now;
16-
DateTimeOffset utcTime = DateTimeOffset.UtcNow;
13+
public static void Main()
14+
{
15+
DateTimeOffset localTime = DateTimeOffset.Now;
16+
DateTimeOffset utcTime = DateTimeOffset.UtcNow;
1717

18-
Console.WriteLine("Difference between local time and UTC: {0}:{1:D2} hours",
19-
(localTime - utcTime).Hours,
20-
(localTime - utcTime).Minutes);
21-
Console.WriteLine("The local time is {0} UTC.",
22-
Enum.GetName(typeof(TimeComparison), localTime.CompareTo(utcTime)));
23-
}
18+
Console.WriteLine("Difference between local time and UTC: {0}:{1:D2} hours",
19+
(localTime - utcTime).Hours,
20+
(localTime - utcTime).Minutes);
21+
Console.WriteLine("The local time is {0} UTC.",
22+
Enum.GetName(typeof(TimeComparison), localTime.CompareTo(utcTime)));
23+
}
2424
}
2525
// Regardless of the local time zone, the example displays
2626
// the following output to the console:

samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Conceptual/cs/Conceptual4.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33

44
public class IntervalArithmetic
55
{
6-
public static void Main()
7-
{
8-
DateTime generalTime = new DateTime(2008, 3, 9, 1, 30, 0);
9-
const string tzName = "Central Standard Time";
10-
TimeSpan twoAndAHalfHours = new TimeSpan(2, 30, 0);
6+
public static void Main()
7+
{
8+
DateTime generalTime = new DateTime(2008, 3, 9, 1, 30, 0);
9+
const string tzName = "Central Standard Time";
10+
TimeSpan twoAndAHalfHours = new TimeSpan(2, 30, 0);
1111

12-
// Instantiate DateTimeOffset value to have correct CST offset
13-
try
14-
{
15-
DateTimeOffset centralTime1 = new DateTimeOffset(generalTime,
16-
TimeZoneInfo.FindSystemTimeZoneById(tzName).GetUtcOffset(generalTime));
12+
// Instantiate DateTimeOffset value to have correct CST offset
13+
try
14+
{
15+
DateTimeOffset centralTime1 = new DateTimeOffset(generalTime,
16+
TimeZoneInfo.FindSystemTimeZoneById(tzName).GetUtcOffset(generalTime));
1717

18-
// Add two and a half hours
19-
DateTimeOffset centralTime2 = centralTime1.Add(twoAndAHalfHours);
20-
// Display result
21-
Console.WriteLine("{0} + {1} hours = {2}", centralTime1,
22-
twoAndAHalfHours.ToString(),
23-
centralTime2);
24-
}
25-
catch (TimeZoneNotFoundException)
26-
{
27-
Console.WriteLine("Unable to retrieve Central Standard Time zone information.");
28-
}
29-
}
18+
// Add two and a half hours
19+
DateTimeOffset centralTime2 = centralTime1.Add(twoAndAHalfHours);
20+
// Display result
21+
Console.WriteLine("{0} + {1} hours = {2}", centralTime1,
22+
twoAndAHalfHours.ToString(),
23+
centralTime2);
24+
}
25+
catch (TimeZoneNotFoundException)
26+
{
27+
Console.WriteLine("Unable to retrieve Central Standard Time zone information.");
28+
}
29+
}
3030
}
3131
// The example displays the following output to the console:
3232
// 3/9/2008 1:30:00 AM -06:00 + 02:30:00 hours = 3/9/2008 4:00:00 AM -06:00

0 commit comments

Comments
 (0)