Skip to content

Commit 169f6d9

Browse files
authored
Convert to interpolated strings (other dirs under samples/snippets/csharp) (#45435)
1 parent c7b0e55 commit 169f6d9

File tree

55 files changed

+494
-719
lines changed

Some content is hidden

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

55 files changed

+494
-719
lines changed

samples/snippets/csharp/VS_Snippets_ADO.NET/DP LINQ to DataSet Examples/CS/Program.cs

Lines changed: 70 additions & 125 deletions
Large diffs are not rendered by default.

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks BulkCopy.Single/CS/source.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data.SqlClient;
33

44
static class Program
@@ -20,7 +20,7 @@ static void Main()
2020
sourceConnection);
2121
long countStart = Convert.ToInt32(
2222
commandRowCount.ExecuteScalar());
23-
Console.WriteLine("Starting row count = {0}", countStart);
23+
Console.WriteLine($"Starting row count = {countStart}");
2424

2525
// Get data from the source table as a SqlDataReader.
2626
SqlCommand commandSourceData = new(
@@ -71,8 +71,8 @@ static void Main()
7171
// table to see how many rows were added.
7272
long countEnd = Convert.ToInt32(
7373
commandRowCount.ExecuteScalar());
74-
Console.WriteLine("Ending row count = {0}", countEnd);
75-
Console.WriteLine("{0} rows were added.", countEnd - countStart);
74+
Console.WriteLine($"Ending row count = {countEnd}");
75+
Console.WriteLine($"{countEnd - countStart} rows were added.");
7676
Console.WriteLine("Press Enter to finish.");
7777
Console.ReadLine();
7878
}

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks ConnectionStrings.Encrypt/CS/source.cs

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

1+
22
using System;
33
using System.Configuration;
44

@@ -45,8 +45,7 @@ static void ToggleConfigEncryption(string exeFile)
4545
// Save the current configuration.
4646
config.Save();
4747

48-
Console.WriteLine("Protected={0}",
49-
section?.SectionInformation.IsProtected);
48+
Console.WriteLine($"Protected={section?.SectionInformation.IsProtected}");
5049
}
5150
catch (Exception ex)
5251
{

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks DataTable.Events/CS/Project.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Library</OutputType>
4+
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net8.0</TargetFrameworks>
66
</PropertyGroup>
77

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks DataTable.Events/CS/source.cs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ static class Class1
66
static void Main()
77
{
88
DataTableEvents();
9-
Console.ReadLine();
109
}
1110
// <Snippet1>
1211
static void DataTableEvents()
@@ -18,7 +17,7 @@ static void DataTableEvents()
1817

1918
// Set the primary key.
2019
table.Columns["id"].Unique = true;
21-
table.PrimaryKey = new DataColumn[] { table.Columns["id"] };
20+
table.PrimaryKey = [table.Columns["id"]];
2221

2322
// Add a RowChanged event handler.
2423
table.RowChanged += Row_Changed;
@@ -33,24 +32,19 @@ static void DataTableEvents()
3332
table.RowDeleting += Row_Deleting;
3433

3534
// Add a ColumnChanged event handler.
36-
table.ColumnChanged +=
37-
Column_Changed;
35+
table.ColumnChanged += Column_Changed;
3836

3937
// Add a ColumnChanging event handler.
40-
table.ColumnChanging +=
41-
Column_Changing;
38+
table.ColumnChanging += Column_Changing;
4239

4340
// Add a TableNewRow event handler.
44-
table.TableNewRow +=
45-
Table_NewRow;
41+
table.TableNewRow += Table_NewRow;
4642

4743
// Add a TableCleared event handler.
48-
table.TableCleared +=
49-
Table_Cleared;
44+
table.TableCleared += Table_Cleared;
5045

5146
// Add a TableClearing event handler.
52-
table.TableClearing +=
53-
Table_Clearing;
47+
table.TableClearing += Table_Clearing;
5448

5549
// Add a customer.
5650
DataRow row = table.NewRow();
@@ -71,29 +65,23 @@ static void DataTableEvents()
7165
}
7266

7367
static void Row_Changed(object sender, DataRowChangeEventArgs e) =>
74-
Console.WriteLine("Row_Changed Event: name={0}; action={1}",
75-
e.Row["name"], e.Action);
68+
Console.WriteLine($"Row_Changed Event: name={e.Row["name"]}; action={e.Action}");
7669

7770
static void Row_Changing(object sender, DataRowChangeEventArgs e) =>
78-
Console.WriteLine("Row_Changing Event: name={0}; action={1}",
79-
e.Row["name"], e.Action);
71+
Console.WriteLine($"Row_Changing Event: name={e.Row["name"]}; action={e.Action}");
8072

8173
static void Row_Deleted(object sender, DataRowChangeEventArgs e) =>
82-
Console.WriteLine("Row_Deleted Event: name={0}; action={1}",
83-
e.Row["name", DataRowVersion.Original], e.Action);
74+
Console.WriteLine($"Row_Deleted Event: name={e.Row["name", DataRowVersion.Original]}; action={e.Action}");
8475

8576
static void Row_Deleting(object sender,
8677
DataRowChangeEventArgs e) =>
87-
Console.WriteLine("Row_Deleting Event: name={0}; action={1}",
88-
e.Row["name"], e.Action);
78+
Console.WriteLine($"Row_Deleting Event: name={e.Row["name"]}; action={e.Action}");
8979

9080
static void Column_Changed(object sender, DataColumnChangeEventArgs e) =>
91-
Console.WriteLine("Column_Changed Event: ColumnName={0}; RowState={1}",
92-
e.Column.ColumnName, e.Row.RowState);
81+
Console.WriteLine($"Column_Changed Event: ColumnName={e.Column.ColumnName}; RowState={e.Row.RowState}");
9382

9483
static void Column_Changing(object sender, DataColumnChangeEventArgs e) =>
95-
Console.WriteLine("Column_Changing Event: ColumnName={0}; RowState={1}",
96-
e.Column.ColumnName, e.Row.RowState);
84+
Console.WriteLine($"Column_Changing Event: ColumnName={e.Column.ColumnName}; RowState={e.Row.RowState}");
9785

9886
static void Table_NewRow(object sender,
9987
DataTableNewRowEventArgs e) =>

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks DbProviderFactories.DbCommand/CS/source.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Configuration;
33
using System.Data.Common;
44
using System.Data.SqlClient;
@@ -27,20 +27,20 @@ static void ExecuteDbCommand(DbConnection connection)
2727
var rows = command.ExecuteNonQuery();
2828

2929
// Display number of rows inserted.
30-
Console.WriteLine("Inserted {0} rows.", rows);
30+
Console.WriteLine($"Inserted {rows} rows.");
3131
}
3232
// Handle data errors.
3333
catch (DbException exDb)
3434
{
3535
Console.WriteLine("DbException.GetType: {0}", exDb.GetType());
36-
Console.WriteLine("DbException.Source: {0}", exDb.Source);
37-
Console.WriteLine("DbException.ErrorCode: {0}", exDb.ErrorCode);
38-
Console.WriteLine("DbException.Message: {0}", exDb.Message);
36+
Console.WriteLine($"DbException.Source: {exDb.Source}");
37+
Console.WriteLine($"DbException.ErrorCode: {exDb.ErrorCode}");
38+
Console.WriteLine($"DbException.Message: {exDb.Message}");
3939
}
4040
// Handle all other exceptions.
4141
catch (Exception ex)
4242
{
43-
Console.WriteLine("Exception.Message: {0}", ex.Message);
43+
Console.WriteLine($"Exception.Message: {ex.Message}");
4444
}
4545
}
4646
}

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks DbProviderFactories.DbCommandData/CS/source.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Configuration;
33
using System.Data;
44
using System.Data.Common;
@@ -42,12 +42,12 @@ static void DbCommandSelect(DbConnection connection)
4242
DbDataReader reader = command.ExecuteReader();
4343
while (reader.Read())
4444
{
45-
Console.WriteLine("{0}. {1}", reader[0], reader[1]);
45+
Console.WriteLine($"{reader[0]}. {reader[1]}");
4646
}
4747
}
4848
catch (Exception ex)
4949
{
50-
Console.WriteLine("Exception.Message: {0}", ex.Message);
50+
Console.WriteLine($"Exception.Message: {ex.Message}");
5151
}
5252
}
5353
}

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks DbProviderFactories.DbDataAdapterModify/CS/source.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data;
33
using System.Data.Common;
44

@@ -41,12 +41,9 @@ static void CreateDataAdapter(string providerName, string connectionString)
4141
adapter.DeleteCommand = builder.GetDeleteCommand();
4242

4343
// Display the CommandText for each command.
44-
Console.WriteLine("InsertCommand: {0}",
45-
adapter.InsertCommand.CommandText);
46-
Console.WriteLine("UpdateCommand: {0}",
47-
adapter.UpdateCommand.CommandText);
48-
Console.WriteLine("DeleteCommand: {0}",
49-
adapter.DeleteCommand.CommandText);
44+
Console.WriteLine($"InsertCommand: {adapter.InsertCommand.CommandText}");
45+
Console.WriteLine($"UpdateCommand: {adapter.UpdateCommand.CommandText}");
46+
Console.WriteLine($"DeleteCommand: {adapter.DeleteCommand.CommandText}");
5047

5148
// Fill the DataTable.
5249
DataTable table = new();
@@ -65,7 +62,7 @@ static void CreateDataAdapter(string providerName, string connectionString)
6562
Console.WriteLine("----List All Rows-----");
6663
foreach (DataRow row in table.Rows)
6764
{
68-
Console.WriteLine("{0} {1}", row[0], row[1]);
65+
Console.WriteLine($"{row[0]} {row[1]}");
6966
}
7067
Console.WriteLine("----After Insert-----");
7168

@@ -79,7 +76,7 @@ static void CreateDataAdapter(string providerName, string connectionString)
7976
Console.WriteLine();
8077
foreach (DataRow row in table.Rows)
8178
{
82-
Console.WriteLine("{0} {1}", row[0], row[1]);
79+
Console.WriteLine($"{row[0]} {row[1]}");
8380
}
8481
Console.WriteLine("----After Update-----");
8582

@@ -96,7 +93,7 @@ static void CreateDataAdapter(string providerName, string connectionString)
9693
Console.WriteLine();
9794
foreach (DataRow row in table.Rows)
9895
{
99-
Console.WriteLine("{0} {1}", row[0], row[1]);
96+
Console.WriteLine($"{row[0]} {row[1]}");
10097
}
10198
Console.WriteLine("----After Delete-----");
10299
Console.WriteLine("Customer XYZZZ was deleted.");

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks LargeValueType.Photo/CS/source.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data;
33
using System.Data.SqlClient;
44
using System.Data.SqlTypes;
@@ -59,7 +59,7 @@ static void TestGetSqlBytes(int documentID, string filePath)
5959
// Ensure that the column isn't null
6060
if (reader.IsDBNull(1))
6161
{
62-
Console.WriteLine("{0} is unavailable.", photoName);
62+
Console.WriteLine($"{photoName} is unavailable.");
6363
}
6464
else
6565
{
@@ -70,7 +70,7 @@ static void TestGetSqlBytes(int documentID, string filePath)
7070

7171
// Save in gif format.
7272
productImage.Save(fileName, ImageFormat.Gif);
73-
Console.WriteLine("Successfully created {0}.", fileName);
73+
Console.WriteLine($"Successfully created {fileName}.");
7474
}
7575
}
7676
}

samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks OleDb.JetAutonumberMerge/CS/source.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data;
33
using System.Data.OleDb;
44
using System.Runtime.Versioning;
@@ -93,7 +93,7 @@ static void MergeIdentityColumns(OleDbConnection connection)
9393
foreach (DataRow row in categories.Rows)
9494
{
9595
{
96-
Console.WriteLine(" {0}: {1}", row[0], row[1]);
96+
Console.WriteLine($" {row[0]}: {row[1]}");
9797
}
9898
}
9999

@@ -107,7 +107,7 @@ static void MergeIdentityColumns(OleDbConnection connection)
107107
foreach (DataRow row in categories.Rows)
108108
{
109109
{
110-
Console.WriteLine(" {0}: {1}", row[0], row[1]);
110+
Console.WriteLine($" {row[0]}: {row[1]}");
111111
}
112112
}
113113
}

0 commit comments

Comments
 (0)