Skip to content

Commit 9b5eda9

Browse files
yishengjin1413BillWagner
authored andcommitted
fix codesnippet from docs repo (#678)
1 parent 5196f1f commit 9b5eda9

File tree

33 files changed

+393
-341
lines changed

33 files changed

+393
-341
lines changed

snippets/csharp/VS_Snippets_VBCSharp/CsLINQGettingStarted/CS/Class1.cs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Collections.Generic;
44
using System.Text;
@@ -15,7 +15,7 @@ class IntroToLINQ
1515
static void Main()
1616
{
1717
// The Three Parts of a LINQ Query:
18-
// 1. Data source.
18+
// 1. Data source.
1919
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
2020

2121
// 2. Query creation.
@@ -138,32 +138,32 @@ static void Main()
138138
// Create the first data source.
139139
List<Student> students = new List<Student>()
140140
{
141-
new Student {First="Svetlana",
142-
Last="Omelchenko",
143-
ID=111,
141+
new Student { First="Svetlana",
142+
Last="Omelchenko",
143+
ID=111,
144144
Street="123 Main Street",
145145
City="Seattle",
146-
Scores= new List<int> {97, 92, 81, 60}},
147-
new Student {First="Claire",
148-
Last="O’Donnell",
146+
Scores= new List<int> { 97, 92, 81, 60 } },
147+
new Student { First="Claire",
148+
Last="O’Donnell",
149149
ID=112,
150150
Street="124 Main Street",
151151
City="Redmond",
152-
Scores= new List<int> {75, 84, 91, 39}},
153-
new Student {First="Sven",
152+
Scores= new List<int> { 75, 84, 91, 39 } },
153+
new Student { First="Sven",
154154
Last="Mortensen",
155155
ID=113,
156156
Street="125 Main Street",
157157
City="Lake City",
158-
Scores= new List<int> {88, 94, 65, 91}},
158+
Scores= new List<int> { 88, 94, 65, 91 } },
159159
};
160160

161161
// Create the second data source.
162162
List<Teacher> teachers = new List<Teacher>()
163163
{
164-
new Teacher {First="Ann", Last="Beebe", ID=945, City = "Seattle"},
165-
new Teacher {First="Alex", Last="Robinson", ID=956, City = "Redmond"},
166-
new Teacher {First="Michiyo", Last="Sato", ID=972, City = "Tacoma"}
164+
new Teacher { First="Ann", Last="Beebe", ID=945, City="Seattle" },
165+
new Teacher { First="Alex", Last="Robinson", ID=956, City="Redmond" },
166+
new Teacher { First="Michiyo", Last="Sato", ID=972, City="Tacoma" }
167167
};
168168

169169
// Create the query.
@@ -209,12 +209,11 @@ static void Main()
209209
// Create the query.
210210
var studentsToXML = new XElement("Root",
211211
from student in students
212-
let x = String.Format("{0},{1},{2},{3}", student.Scores[0],
213-
student.Scores[1], student.Scores[2], student.Scores[3])
212+
let scores = string.Join(",", student.Scores)
214213
select new XElement("student",
215214
new XElement("First", student.First),
216215
new XElement("Last", student.Last),
217-
new XElement("Scores", x)
216+
new XElement("Scores", scores)
218217
) // end "student"
219218
); // end "Root"
220219

@@ -259,7 +258,7 @@ static void Main()
259258
// Query.
260259
IEnumerable<string> query =
261260
from rad in radii
262-
select String.Format("Area = {0}", (rad * rad) * 3.14);
261+
select $"Area = {rad * rad * Math.PI:F2}";
263262

264263
// Query execution.
265264
foreach (string s in query)
@@ -272,8 +271,8 @@ from rad in radii
272271
}
273272
/* Output:
274273
Area = 3.14
275-
Area = 12.56
276-
Area = 28.26
274+
Area = 12.57
275+
Area = 28.27
277276
*/
278277
// </snippet10>
279278

@@ -291,18 +290,18 @@ public class Student
291290
// Create a data source by using a collection initializer.
292291
static List<Student> students = new List<Student>
293292
{
294-
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 92, 81, 60}},
295-
new Student {First="Claire", Last="O'Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}},
296-
new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {88, 94, 65, 91}},
297-
new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {97, 89, 85, 82}},
298-
new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {35, 72, 91, 70}},
299-
new Student {First="Fadi", Last="Fakhouri", ID=116, Scores= new List<int> {99, 86, 90, 94}},
300-
new Student {First="Hanying", Last="Feng", ID=117, Scores= new List<int> {93, 92, 80, 87}},
301-
new Student {First="Hugo", Last="Garcia", ID=118, Scores= new List<int> {92, 90, 83, 78}},
302-
new Student {First="Lance", Last="Tucker", ID=119, Scores= new List<int> {68, 79, 88, 92}},
303-
new Student {First="Terry", Last="Adams", ID=120, Scores= new List<int> {99, 82, 81, 79}},
304-
new Student {First="Eugene", Last="Zabokritski", ID=121, Scores= new List<int> {96, 85, 91, 60}},
305-
new Student {First="Michael", Last="Tucker", ID=122, Scores= new List<int> {94, 92, 91, 91} }
293+
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 92, 81, 60}},
294+
new Student {First="Claire", Last="O'Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}},
295+
new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {88, 94, 65, 91}},
296+
new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {97, 89, 85, 82}},
297+
new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {35, 72, 91, 70}},
298+
new Student {First="Fadi", Last="Fakhouri", ID=116, Scores= new List<int> {99, 86, 90, 94}},
299+
new Student {First="Hanying", Last="Feng", ID=117, Scores= new List<int> {93, 92, 80, 87}},
300+
new Student {First="Hugo", Last="Garcia", ID=118, Scores= new List<int> {92, 90, 83, 78}},
301+
new Student {First="Lance", Last="Tucker", ID=119, Scores= new List<int> {68, 79, 88, 92}},
302+
new Student {First="Terry", Last="Adams", ID=120, Scores= new List<int> {99, 82, 81, 79}},
303+
new Student {First="Eugene", Last="Zabokritski", ID=121, Scores= new List<int> {96, 85, 91, 60}},
304+
new Student {First="Michael", Last="Tucker", ID=122, Scores= new List<int> {94, 92, 91, 91}}
306305
};
307306
//</snippet11>
308307

snippets/csharp/VS_Snippets_VBCSharp/CsProgGuideTypes/CS/Class1.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//<snippet5555>
1+
//<snippet5555>
22
using System;
33
using System.Linq;
44
using System.Collections;
@@ -340,7 +340,7 @@ static void Main()
340340
// Change the value of i.
341341
i = 456;
342342

343-
// The change in i does not effect the value stored in o.
343+
// The change in i doesn't affect the value stored in o.
344344
System.Console.WriteLine("The value-type value = {0}", i);
345345
System.Console.WriteLine("The object-type value = {0}", o);
346346
}
@@ -449,12 +449,11 @@ static void Main(string[] args)
449449
{
450450
// Get the integral value of the character.
451451
int value = Convert.ToInt32(letter);
452-
// Convert the decimal value to a hexadecimal value in string form.
453-
string hexOutput = String.Format("{0:X}", value);
454-
Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
452+
// Convert the integer value to a hexadecimal value in string form.
453+
Console.WriteLine($"Hexadecimal value of {letter} is {value:X}");
455454
}
456455
/* Output:
457-
Hexadecimal value of H is 48
456+
Hexadecimal value of H is 48
458457
Hexadecimal value of e is 65
459458
Hexadecimal value of l is 6C
460459
Hexadecimal value of l is 6C
@@ -472,7 +471,7 @@ Hexadecimal value of ! is 21
472471
//<Snippet31>
473472
string hexValues = "48 65 6C 6C 6F 20 57 6F 72 6C 64 21";
474473
string[] hexValuesSplit = hexValues.Split(' ');
475-
foreach (String hex in hexValuesSplit)
474+
foreach (string hex in hexValuesSplit)
476475
{
477476
// Convert the number expressed in base-16 to an integer.
478477
int value = Convert.ToInt32(hex, 16);
@@ -556,7 +555,7 @@ public string GetName(int ID)
556555
static void Main()
557556
{
558557
//<snippet34>
559-
// Implicit conversion. num long can
558+
// Implicit conversion. A long can
560559
// hold any value an int can hold, and more!
561560
int num = 2147483647;
562561
long bigNum = num;
@@ -715,7 +714,7 @@ void UseAsWithNullable(System.ValueType val)
715714

716715
//<snippet41>
717716

718-
//using System;
717+
using System;
719718

720719
class Animal
721720
{
@@ -735,8 +734,8 @@ static void Main()
735734
Test(new Mammal());
736735

737736
// Keep the console window open in debug mode.
738-
System.Console.WriteLine("Press any key to exit.");
739-
System.Console.ReadKey();
737+
Console.WriteLine("Press any key to exit.");
738+
Console.ReadKey();
740739
}
741740

742741
static void Test(Animal a)

snippets/csharp/VS_Snippets_VBCSharp/csProgGuideArrays/CS/Arrays.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,20 @@ void test()
438438
//</Snippet21>
439439

440440
//<Snippet22>
441-
int[][] jaggedArray2 = new int[][]
441+
int[][] jaggedArray2 = new int[][]
442442
{
443-
new int[] {1,3,5,7,9},
444-
new int[] {0,2,4,6},
445-
new int[] {11,22}
443+
new int[] { 1, 3, 5, 7, 9 },
444+
new int[] { 0, 2, 4, 6 },
445+
new int[] { 11, 22 }
446446
};
447447
//</Snippet22>
448448

449449
//<Snippet23>
450-
int[][] jaggedArray3 =
450+
int[][] jaggedArray3 =
451451
{
452-
new int[] {1,3,5,7,9},
453-
new int[] {0,2,4,6},
454-
new int[] {11,22}
452+
new int[] { 1, 3, 5, 7, 9 },
453+
new int[] { 0, 2, 4, 6 },
454+
new int[] { 11, 22 }
455455
};
456456
//</Snippet23>
457457

snippets/csharp/VS_Snippets_VBCSharp/csProgGuideDelegates/CS/Delegates.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Drawing;
55

66
public delegate int PerformCalculation(int x, int y);
7-
87
class DelegatesIntro
98
{
109

@@ -152,7 +151,6 @@ public void DoWork()
152151

153152
//<Snippet20>
154153
public delegate int PerformCalculation(int x, int y);
155-
156154
//</Snippet20>
157155

158156

@@ -356,7 +354,7 @@ static void Main()
356354
p("The delegate using the anonymous method is called.");
357355

358356
// The delegate instantiation using a named method "DoWork".
359-
p = new Printer(TestClass.DoWork);
357+
p = DoWork;
360358

361359
// Results from the old style delegate call.
362360
p("The delegate using the named method is called.");
@@ -665,7 +663,7 @@ internal decimal AveragePrice()
665663
}
666664

667665
// Class to test the book database:
668-
class TestBookDB
666+
class Test
669667
{
670668
// Print the title of the book.
671669
static void PrintTitle(Book b)

snippets/csharp/VS_Snippets_VBCSharp/csProgGuideDocComments/CS/DocComments.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ namespace Wrap2
3838
/// text for class TestClass
3939
public class TestClass
4040
{
41-
/// <summary>
42-
/// <c>DoWork</c> is a method in the <c>TestClass</c> class.
41+
/// <summary><c>DoWork</c> is a method in the <c>TestClass</c> class.
4342
/// </summary>
4443
public static void DoWork(int Int1)
4544
{
@@ -262,9 +261,9 @@ namespace Wrap7
262261
public class TestClass
263262
{
264263
/// <summary>DoWork is a method in the TestClass class.
265-
/// The <paramref name="Int1"/> parameter takes a number.
264+
/// The <paramref name="int1"/> parameter takes a number.
266265
/// </summary>
267-
public static void DoWork(int Int1)
266+
public static void DoWork(int int1)
268267
{
269268
}
270269

0 commit comments

Comments
 (0)