From 59c02308c1106365367e13a3035cfda1e102b9ca Mon Sep 17 00:00:00 2001 From: volkan-yazilim Date: Mon, 7 Jan 2019 19:49:56 +0200 Subject: [PATCH 1/3] added output lines (#555) --- .../keywords/in-ref-out-modifier/OutParameterModifier.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/snippets/csharp/language-reference/keywords/in-ref-out-modifier/OutParameterModifier.cs b/snippets/csharp/language-reference/keywords/in-ref-out-modifier/OutParameterModifier.cs index b5d1cb4feac..2c7b8bef0f0 100644 --- a/snippets/csharp/language-reference/keywords/in-ref-out-modifier/OutParameterModifier.cs +++ b/snippets/csharp/language-reference/keywords/in-ref-out-modifier/OutParameterModifier.cs @@ -43,6 +43,12 @@ void Method(out int answer, out string message, out string stillNull) Console.WriteLine(argNumber); Console.WriteLine(argMessage); Console.WriteLine(argDefault == null); + + // The example displays the following output: + // 44 + // I've been returned + // True + // } From f5d62c02988a59a5d2b4a5b60c911a04e9565b99 Mon Sep 17 00:00:00 2001 From: volkan-yazilim Date: Mon, 7 Jan 2019 19:55:10 +0200 Subject: [PATCH 2/3] Re-organized the order of methods, added result (#554) --- .../RefParameterModifier.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/snippets/csharp/language-reference/keywords/in-ref-out-modifier/RefParameterModifier.cs b/snippets/csharp/language-reference/keywords/in-ref-out-modifier/RefParameterModifier.cs index 7ec9ab83050..c4898c8a8d5 100644 --- a/snippets/csharp/language-reference/keywords/in-ref-out-modifier/RefParameterModifier.cs +++ b/snippets/csharp/language-reference/keywords/in-ref-out-modifier/RefParameterModifier.cs @@ -40,6 +40,16 @@ public Product(string name, int newID) public int ItemID { get; set; } } + private static void ChangeByReference(ref Product itemRef) + { + // Change the address that is stored in the itemRef parameter. + itemRef = new Product("Stapler", 99999); + + // You can change the value of one of the properties of + // itemRef. The change happens to item in Main as well. + itemRef.ItemID = 12345; + } + private static void ModifyProductsByReference() { // Declare an instance of Product and display its initial values. @@ -52,16 +62,11 @@ private static void ModifyProductsByReference() System.Console.WriteLine("Back in Main. Name: {0}, ID: {1}\n", item.ItemName, item.ItemID); } - - private static void ChangeByReference(ref Product itemRef) - { - // Change the address that is stored in the itemRef parameter. - itemRef = new Product("Stapler", 99999); - - // You can change the value of one of the properties of - // itemRef. The change happens to item in Main as well. - itemRef.ItemID = 12345; - } + + // This method displays the following output: + // Original values in Main. Name: Fasteners, ID: 54321 + // Back in Main. Name: Stapler, ID: 12345 + // private static void BookCollectionExample() From 525fbb7876ca9f8f0f781e73abe88df76846eec6 Mon Sep 17 00:00:00 2001 From: Theano Petersen Date: Mon, 7 Jan 2019 15:09:28 -0800 Subject: [PATCH 3/3] replace paths with mydocs variable for how-to-enumerate-directories-and-files (#547) * replace paths with mydocs variable * Apply suggestions from code review Co-Authored-By: v-thepet * fixes per review --- .../cs/program.cs | 10 ++++-- .../cs/program.cs | 33 ++++++++++--------- .../cs/program.cs | 7 ++-- .../system.io.enumdirs1/cs/program.cs | 5 +-- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/cs/program.cs b/snippets/csharp/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/cs/program.cs index 0211a6c35ea..46bdcb974c4 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/cs/program.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/cs/program.cs @@ -9,7 +9,11 @@ static void Main(string[] args) { try { - var files = from file in Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories) + // Set a variable to the My Documents path. + string docPath = + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + + var files = from file in Directory.EnumerateFiles(docPath, "*.txt", SearchOption.AllDirectories) from line in File.ReadLines(file) where line.Contains("Microsoft") select new @@ -22,7 +26,7 @@ where line.Contains("Microsoft") { Console.WriteLine("{0}\t{1}", f.File, f.Line); } - Console.WriteLine("{0} files found.", files.Count().ToString()); + Console.WriteLine("{0} files found.", files.Count().ToString()); } catch (UnauthorizedAccessException UAEx) { @@ -34,4 +38,4 @@ where line.Contains("Microsoft") } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumdirs/cs/program.cs b/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumdirs/cs/program.cs index 431680da14e..b667e1fe2b9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumdirs/cs/program.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumdirs/cs/program.cs @@ -1,4 +1,5 @@ -using System; +// +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,23 +11,25 @@ class Program { static void Main(string[] args) { -// -DirectoryInfo dirPrograms = new DirectoryInfo(@"c:\program files"); -DateTime StartOf2009 = new DateTime(2009, 01, 01); + // Set a variable to the My Documents path. + string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); -var dirs = from dir in dirPrograms.EnumerateDirectories() - where dir.CreationTimeUtc < StartOf2009 - select new - { - ProgDir = dir, - }; + DirectoryInfo dirPrograms = new DirectoryInfo(docPath); + DateTime StartOf2009 = new DateTime(2009, 01, 01); -foreach (var di in dirs) -{ - Console.WriteLine("{0}", di.ProgDir.Name); -} -// + var dirs = from dir in dirPrograms.EnumerateDirectories() + where dir.CreationTimeUtc > StartOf2009 + select new + { + ProgDir = dir, + }; + + foreach (var di in dirs) + { + Console.WriteLine("{0}", di.ProgDir.Name); + } } } } +// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumeratedirectories/cs/program.cs b/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumeratedirectories/cs/program.cs index b05dd680830..3a50e8bbdb1 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumeratedirectories/cs/program.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.io.directoryinfo.enumeratedirectories/cs/program.cs @@ -6,7 +6,11 @@ class Program { static void Main(string[] args) { - DirectoryInfo diTop = new DirectoryInfo(@"d:\"); + // Set a variable to the My Documents path. + string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + + DirectoryInfo diTop = new DirectoryInfo(docPath); + try { foreach (var fi in diTop.EnumerateFiles()) @@ -66,4 +70,3 @@ static void Main(string[] args) } } // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.io.enumdirs1/cs/program.cs b/snippets/csharp/VS_Snippets_CLR_System/system.io.enumdirs1/cs/program.cs index c19df54026a..2eac85214ed 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.io.enumdirs1/cs/program.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.io.enumdirs1/cs/program.cs @@ -10,9 +10,10 @@ private static void Main(string[] args) { try { - string dirPath = @"\\archives\2009\reports"; + // Set a variable to the My Documents path. + string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - List dirs = new List(Directory.EnumerateDirectories(dirPath)); + List dirs = new List(Directory.EnumerateDirectories(docPath)); foreach (var dir in dirs) {