Skip to content

Commit dc9b81c

Browse files
pkulikovRon Petrusha
authored andcommitted
Fix snippet error (#6172)
* Fix snippet error * Addressed feedback
1 parent a0dd3d7 commit dc9b81c

File tree

4 files changed

+75
-53
lines changed

4 files changed

+75
-53
lines changed

docs/csharp/programming-guide/concepts/linq/how-to-join-content-from-dissimilar-files-linq.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
title: "How to: Join Content from Dissimilar Files (LINQ) (C#)"
3-
ms.date: 07/20/2015
3+
ms.date: 06/27/2018
44
ms.assetid: aa2d12a6-70a9-492f-a6db-b2b850d46811
55
---
66
# How to: Join Content from Dissimilar Files (LINQ) (C#)
7+
78
This example shows how to join data from two comma-delimited files that share a common value that is used as a matching key. This technique can be useful if you have to combine data from two spreadsheets, or from a spreadsheet and from a file that has another format, into a new file. You can modify the example to work with any kind of structured text.
89

9-
### To create the data files
10+
## To create the data files
1011

11-
1. Copy the following lines into a file that is named scores.csv and save it to your project folder. The file represents spreadsheet data. Column 1 is the student's ID, and columns 2 through 5 are test scores.
12+
1. Copy the following lines into a file that is named *scores.csv* and save it to your project folder. The file represents spreadsheet data. Column 1 is the student's ID, and columns 2 through 5 are test scores.
1213

1314
```
1415
111, 97, 92, 81, 60
@@ -25,7 +26,7 @@ This example shows how to join data from two comma-delimited files that share a
2526
122, 94, 92, 91, 91
2627
```
2728
28-
2. Copy the following lines into a file that is named names.csv and save it to your project folder. The file represents a spreadsheet that contains the student's last name, first name, and student ID.
29+
2. Copy the following lines into a file that is named *names.csv* and save it to your project folder. The file represents a spreadsheet that contains the student's last name, first name, and student ID.
2930
3031
```
3132
Omelchenko,Svetlana,111
@@ -43,8 +44,12 @@ This example shows how to join data from two comma-delimited files that share a
4344
```
4445
4546
## Example
46-
47-
```csharp
47+
48+
```csharp
49+
using System;
50+
using System.Collections.Generic;
51+
using System.Linq;
52+
4853
class JoinStrings
4954
{
5055
static void Main()
@@ -72,7 +77,7 @@ class JoinStrings
7277
let nameFields = name.Split(',')
7378
from id in scores
7479
let scoreFields = id.Split(',')
75-
where nameFields[2] == scoreFields[0]
80+
where Convert.ToInt32(nameFields[2]) == Convert.ToInt32(scoreFields[0])
7681
select nameFields[0] + "," + scoreFields[1] + "," + scoreFields[2]
7782
+ "," + scoreFields[3] + "," + scoreFields[4];
7883
@@ -96,26 +101,32 @@ class JoinStrings
96101
}
97102
}
98103
/* Output:
99-
Merge two spreadsheets:
100-
Adams, 99, 82, 81, 79
101-
Fakhouri, 99, 86, 90, 94
102-
Feng, 93, 92, 80, 87
103-
Garcia, 97, 89, 85, 82
104-
Garcia, 35, 72, 91, 70
105-
Garcia, 92, 90, 83, 78
106-
Mortensen, 88, 94, 65, 91
107-
O'Donnell, 75, 84, 91, 39
108-
Omelchenko, 97, 92, 81, 60
109-
Tucker, 68, 79, 88, 92
110-
Tucker, 94, 92, 91, 91
111-
Zabokritski, 96, 85, 91, 60
112-
12 total names in list
104+
Merge two spreadsheets:
105+
Omelchenko, 97, 92, 81, 60
106+
O'Donnell, 75, 84, 91, 39
107+
Mortensen, 88, 94, 65, 91
108+
Garcia, 97, 89, 85, 82
109+
Garcia, 35, 72, 91, 70
110+
Fakhouri, 99, 86, 90, 94
111+
Feng, 93, 92, 80, 87
112+
Garcia, 92, 90, 83, 78
113+
Tucker, 68, 79, 88, 92
114+
Adams, 99, 82, 81, 79
115+
Zabokritski, 96, 85, 91, 60
116+
Tucker, 94, 92, 91, 91
117+
12 total names in list
113118
*/
114-
```
115-
116-
## Compiling the Code
117-
Create a project that targets the .NET Framework version 3.5 or higher, with a reference to System.Core.dll and `using` directives for the System.Linq and System.IO namespaces.
119+
```
120+
121+
## Compiling the code
122+
123+
Create and compile a project that targets one of the following options:
124+
125+
- .NET Framework version 3.5 with a reference to System.Core.dll.
126+
- .NET Framework version 4.0 or higher.
127+
- .NET Core version 1.0 or higher.
118128

119-
## See Also
129+
## See also
130+
120131
[LINQ and Strings (C#)](../../../../csharp/programming-guide/concepts/linq/linq-and-strings.md)
121132
[LINQ and File Directories (C#)](../../../../csharp/programming-guide/concepts/linq/linq-and-file-directories.md)

docs/csharp/programming-guide/concepts/linq/how-to-populate-object-collections-from-multiple-sources-linq.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ foreach (var student in queryNamesScores2)
137137

138138
Create and compile a project that targets one of the following options:
139139

140-
- .NET Framework version 3.5 or higher with a reference to System.Core.dll.
140+
- .NET Framework version 3.5 with a reference to System.Core.dll.
141+
- .NET Framework version 4.0 or higher.
141142
- .NET Core version 1.0 or higher.
142143

143144
## See also

docs/visual-basic/programming-guide/concepts/linq/how-to-join-content-from-dissimilar-files-linq.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22
title: "How to: Join Content from Dissimilar Files (LINQ) (Visual Basic)"
3-
ms.date: 07/20/2015
3+
ms.date: 06/27/2018
44
ms.assetid: e7530857-c467-41ea-9730-84e6b1065a4d
55
---
66
# How to: Join Content from Dissimilar Files (LINQ) (Visual Basic)
7+
78
This example shows how to join data from two comma-delimited files that share a common value that is used as a matching key. This technique can be useful if you have to combine data from two spreadsheets, or from a spreadsheet and from a file that has another format, into a new file. You can modify the example to work with any kind of structured text.
89

9-
### To create the data files
10+
## To create the data files
1011

1112
1. Copy the following lines into a file that is named scores.csv and save it to your project folder. The file represents spreadsheet data. Column 1 is the student's ID, and columns 2 through 5 are test scores.
1213

@@ -43,8 +44,11 @@ This example shows how to join data from two comma-delimited files that share a
4344
```
4445
4546
## Example
46-
47-
```vb
47+
48+
```vb
49+
Imports System.Collections.Generic
50+
Imports System.Linq
51+
4852
Class JoinStrings
4953
5054
Shared Sub Main()
@@ -71,7 +75,7 @@ Class JoinStrings
7175
Let n = name.Split(New Char() {","})
7276
From id In scores
7377
Let n2 = id.Split(New Char() {","})
74-
Where n(2) = n2(0)
78+
Where Convert.ToInt32(n(2)) = Convert.ToInt32(n2(0))
7579
Select n(0) & "," & n(1) & "," & n2(0) & "," & n2(1) & "," &
7680
n2(2) & "," & n2(3)
7781
@@ -95,25 +99,31 @@ Class JoinStrings
9599
End Sub
96100
End Class
97101
' Output:
98-
'Merge two spreadsheets:
99-
'Adams,Terry,120, 99, 82, 81
100-
'Fakhouri,Fadi,116, 99, 86, 90
101-
'Feng,Hanying,117, 93, 92, 80
102-
'Garcia,Cesar,114, 97, 89, 85
103-
'Garcia,Debra,115, 35, 72, 91
104-
'Garcia,Hugo,118, 92, 90, 83
105-
'Mortensen,Sven,113, 88, 94, 65
106-
'O'Donnell,Claire,112, 75, 84, 91
107-
'Omelchenko,Svetlana,111, 97, 92, 81
108-
'Tucker,Lance,119, 68, 79, 88
109-
'Tucker,Michael,122, 94, 92, 91
110-
'Zabokritski,Eugene,121, 96, 85, 91
111-
'12 total names in list
102+
' Merge two spreadsheets:
103+
' Omelchenko, 97, 92, 81, 60
104+
' O'Donnell, 75, 84, 91, 39
105+
' Mortensen, 88, 94, 65, 91
106+
' Garcia, 97, 89, 85, 82
107+
' Garcia, 35, 72, 91, 70
108+
' Fakhouri, 99, 86, 90, 94
109+
' Feng, 93, 92, 80, 87
110+
' Garcia, 92, 90, 83, 78
111+
' Tucker, 68, 79, 88, 92
112+
' Adams, 99, 82, 81, 79
113+
' Zabokritski, 96, 85, 91, 60
114+
' Tucker, 94, 92, 91, 91
115+
' 12 total names in list
112116
```
113-
114-
## Compiling the Code
115-
Create a project that targets the .NET Framework version 3.5 or higher with a reference to System.Core.dll and a `Imports` statement for the System.Linq namespace.
116-
117-
## See Also
117+
118+
## Compiling the code
119+
120+
Create and compile a project that targets one of the following options:
121+
122+
- .NET Framework version 3.5 with a reference to System.Core.dll.
123+
- .NET Framework version 4.0 or higher.
124+
- .NET Core version 1.0 or higher.
125+
126+
## See also
127+
118128
[LINQ and Strings (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/linq-and-strings.md)
119129
[LINQ and File Directories (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/linq-and-file-directories.md)

docs/visual-basic/programming-guide/concepts/linq/how-to-populate-object-collections-from-multiple-sources-linq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This example shows how to merge data from different sources into a sequence of n
1919
The following example shows how to use a named type `Student` to store merged data from two in-memory collections of strings that simulate spreadsheet data in .csv format. The first collection of strings represents the student names and IDs, and the second collection represents the student ID (in the first column) and four exam scores. The ID is used as the foreign key.
2020

2121
```vb
22-
Imports System
2322
Imports System.Collections.Generic
2423
Imports System.Linq
2524

@@ -127,7 +126,8 @@ Next
127126

128127
Create and compile a project that targets one of the following options:
129128

130-
- .NET Framework version 3.5 or higher with a reference to System.Core.dll.
129+
- .NET Framework version 3.5 with a reference to System.Core.dll.
130+
- .NET Framework version 4.0 or higher.
131131
- .NET Core version 1.0 or higher.
132132

133133
## See also

0 commit comments

Comments
 (0)