Skip to content

Commit 7857258

Browse files
authored
Merge pull request #556 from dotnet/master
Update live with current master
2 parents 1378ee0 + 525fbb7 commit 7857258

File tree

6 files changed

+54
-32
lines changed

6 files changed

+54
-32
lines changed

snippets/csharp/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/cs/program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ static void Main(string[] args)
99
{
1010
try
1111
{
12-
var files = from file in Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories)
12+
// Set a variable to the My Documents path.
13+
string docPath =
14+
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
15+
16+
var files = from file in Directory.EnumerateFiles(docPath, "*.txt", SearchOption.AllDirectories)
1317
from line in File.ReadLines(file)
1418
where line.Contains("Microsoft")
1519
select new
@@ -22,7 +26,7 @@ where line.Contains("Microsoft")
2226
{
2327
Console.WriteLine("{0}\t{1}", f.File, f.Line);
2428
}
25-
Console.WriteLine("{0} files found.", files.Count().ToString());
29+
Console.WriteLine("{0} files found.", files.Count().ToString());
2630
}
2731
catch (UnauthorizedAccessException UAEx)
2832
{
@@ -34,4 +38,4 @@ where line.Contains("Microsoft")
3438
}
3539
}
3640
}
37-
// </Snippet1>
41+
// </Snippet1>
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
// <Snippet1>
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -10,23 +11,25 @@ class Program
1011
{
1112
static void Main(string[] args)
1213
{
13-
// <Snippet1>
14-
DirectoryInfo dirPrograms = new DirectoryInfo(@"c:\program files");
15-
DateTime StartOf2009 = new DateTime(2009, 01, 01);
14+
// Set a variable to the My Documents path.
15+
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
1616

17-
var dirs = from dir in dirPrograms.EnumerateDirectories()
18-
where dir.CreationTimeUtc < StartOf2009
19-
select new
20-
{
21-
ProgDir = dir,
22-
};
17+
DirectoryInfo dirPrograms = new DirectoryInfo(docPath);
18+
DateTime StartOf2009 = new DateTime(2009, 01, 01);
2319

24-
foreach (var di in dirs)
25-
{
26-
Console.WriteLine("{0}", di.ProgDir.Name);
27-
}
28-
// </Snippet1>
20+
var dirs = from dir in dirPrograms.EnumerateDirectories()
21+
where dir.CreationTimeUtc > StartOf2009
22+
select new
23+
{
24+
ProgDir = dir,
25+
};
26+
27+
foreach (var di in dirs)
28+
{
29+
Console.WriteLine("{0}", di.ProgDir.Name);
30+
}
2931

3032
}
3133
}
3234
}
35+
// </Snippet1>

snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumeratedirectories/cs/program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9-
DirectoryInfo diTop = new DirectoryInfo(@"d:\");
9+
// Set a variable to the My Documents path.
10+
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
11+
12+
DirectoryInfo diTop = new DirectoryInfo(docPath);
13+
1014
try
1115
{
1216
foreach (var fi in diTop.EnumerateFiles())
@@ -66,4 +70,3 @@ static void Main(string[] args)
6670
}
6771
}
6872
// </Snippet1>
69-

snippets/csharp/VS_Snippets_CLR_System/system.io.enumdirs1/cs/program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ private static void Main(string[] args)
1010
{
1111
try
1212
{
13-
string dirPath = @"\\archives\2009\reports";
13+
// Set a variable to the My Documents path.
14+
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
1415

15-
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
16+
List<string> dirs = new List<string>(Directory.EnumerateDirectories(docPath));
1617

1718
foreach (var dir in dirs)
1819
{

snippets/csharp/language-reference/keywords/in-ref-out-modifier/OutParameterModifier.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ void Method(out int answer, out string message, out string stillNull)
4343
Console.WriteLine(argNumber);
4444
Console.WriteLine(argMessage);
4545
Console.WriteLine(argDefault == null);
46+
47+
// The example displays the following output:
48+
// 44
49+
// I've been returned
50+
// True
51+
4652
// </Snippet3>
4753
}
4854

snippets/csharp/language-reference/keywords/in-ref-out-modifier/RefParameterModifier.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public Product(string name, int newID)
4040
public int ItemID { get; set; }
4141
}
4242

43+
private static void ChangeByReference(ref Product itemRef)
44+
{
45+
// Change the address that is stored in the itemRef parameter.
46+
itemRef = new Product("Stapler", 99999);
47+
48+
// You can change the value of one of the properties of
49+
// itemRef. The change happens to item in Main as well.
50+
itemRef.ItemID = 12345;
51+
}
52+
4353
private static void ModifyProductsByReference()
4454
{
4555
// Declare an instance of Product and display its initial values.
@@ -52,16 +62,11 @@ private static void ModifyProductsByReference()
5262
System.Console.WriteLine("Back in Main. Name: {0}, ID: {1}\n",
5363
item.ItemName, item.ItemID);
5464
}
55-
56-
private static void ChangeByReference(ref Product itemRef)
57-
{
58-
// Change the address that is stored in the itemRef parameter.
59-
itemRef = new Product("Stapler", 99999);
60-
61-
// You can change the value of one of the properties of
62-
// itemRef. The change happens to item in Main as well.
63-
itemRef.ItemID = 12345;
64-
}
65+
66+
// This method displays the following output:
67+
// Original values in Main. Name: Fasteners, ID: 54321
68+
// Back in Main. Name: Stapler, ID: 12345
69+
6570
// </Snippet3>
6671

6772
private static void BookCollectionExample()

0 commit comments

Comments
 (0)