Skip to content

Commit b58f1c2

Browse files
author
Ron Petrusha
authored
Merge pull request #548 from dotnet/master
Update Live with current Master
2 parents f1ed66c + 6d7ab3a commit b58f1c2

File tree

56 files changed

+1652
-982
lines changed

Some content is hidden

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

56 files changed

+1652
-982
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// <SnippetUsingStatic>
2+
using static System.Console;
3+
// </SnippetUsingStatic>
4+
using System.Linq;
5+
6+
public class Person
7+
{
8+
public string FirstName { get; private set; }
9+
public string LastName { get; private set; }
10+
11+
// <SnippetMiddleName>
12+
public string MiddleName { get; } = "";
13+
14+
public Person(string first, string middle, string last)
15+
{
16+
FirstName = first;
17+
MiddleName = middle;
18+
LastName = last;
19+
}
20+
// </SnippetMiddleName>
21+
22+
public Person(string first, string last)
23+
{
24+
FirstName = first;
25+
LastName = last;
26+
}
27+
28+
// <SnippetStringInterpolation>
29+
public override string ToString() => $"{FirstName} {LastName}";
30+
public string AllCaps() => $"{FirstName.ToUpper()} {LastName.ToUpper()}";
31+
// </SnippetStringInterpolation>
32+
}
33+
34+
public class Program
35+
{
36+
public static void Main()
37+
{
38+
// <SnippetInterpolationMain>
39+
var p = new Person("Bill", "Wagner");
40+
WriteLine($"The name, in all caps {p.AllCaps()}");
41+
WriteLine($"The name is {p}");
42+
// </SnippetInterpolationMain>
43+
// <SnippetPhrases>
44+
var phrase = "the quick brown fox jumps over the lazy dog";
45+
var wordLength = from word in phrase.Split(" ") select word.Length;
46+
var average = wordLength.Average();
47+
WriteLine(average);
48+
// </SnippetPhrases>
49+
}
50+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<RootNamespace>csharp6_finished</RootNamespace>
7+
<LangVersion>6</LangVersion>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
public class Person
4+
{
5+
public string FirstName { get; private set; }
6+
public string LastName { get; private set; }
7+
8+
public Person(string first, string last)
9+
{
10+
FirstName = first;
11+
LastName = last;
12+
}
13+
14+
public override string ToString()
15+
{
16+
return FirstName + " " + LastName;
17+
}
18+
19+
public string AllCaps()
20+
{
21+
FirstName = FirstName.ToUpper();
22+
LastName = LastName.ToUpper();
23+
return ToString();
24+
}
25+
}
26+
27+
public class Program
28+
{
29+
public static void Main()
30+
{
31+
var p = new Person("Bill", "Wagner");
32+
Console.WriteLine("The name, in all caps " + p.AllCaps());
33+
Console.WriteLine("The name " + p);
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<LangVersion>6</LangVersion>
5+
<OutputType>Exe</OutputType>
6+
<TargetFramework>netcoreapp2.2</TargetFramework>
7+
<RootNamespace>csharp6_starter</RootNamespace>
8+
</PropertyGroup>
9+
10+
</Project>

snippets/csharp/VS_Snippets_CLR/Diag_Process_MemoryProperties64/CS/source.cs

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ class ProcessMonitorSample
1313
{
1414
public static void Main()
1515
{
16-
1716
// Define variables to track the peak
1817
// memory usage of the process.
1918
long peakPagedMem = 0,
2019
peakWorkingSet = 0,
2120
peakVirtualMem = 0;
2221

23-
Process myProcess = null;
24-
25-
try
22+
// Start the process.
23+
using (Process myProcess = Process.Start("NotePad.exe"))
2624
{
27-
// Start the process.
28-
myProcess = Process.Start("NotePad.exe");
29-
3025
// Display the process statistics until
3126
// the user closes the program.
3227
do
@@ -40,25 +35,17 @@ public static void Main()
4035

4136
// Display current process statistics.
4237

43-
Console.WriteLine("{0} -", myProcess.ToString());
38+
Console.WriteLine($"{myProcess} -");
4439
Console.WriteLine("-------------------------------------");
4540

46-
Console.WriteLine(" physical memory usage: {0}",
47-
myProcess.WorkingSet64);
48-
Console.WriteLine(" base priority: {0}",
49-
myProcess.BasePriority);
50-
Console.WriteLine(" priority class: {0}",
51-
myProcess.PriorityClass);
52-
Console.WriteLine(" user processor time: {0}",
53-
myProcess.UserProcessorTime);
54-
Console.WriteLine(" privileged processor time: {0}",
55-
myProcess.PrivilegedProcessorTime);
56-
Console.WriteLine(" total processor time: {0}",
57-
myProcess.TotalProcessorTime);
58-
Console.WriteLine(" PagedSystemMemorySize64: {0}",
59-
myProcess.PagedSystemMemorySize64);
60-
Console.WriteLine(" PagedMemorySize64: {0}",
61-
myProcess.PagedMemorySize64);
41+
Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}");
42+
Console.WriteLine($" Base priority : {myProcess.BasePriority}");
43+
Console.WriteLine($" Priority class : {myProcess.PriorityClass}");
44+
Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}");
45+
Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}");
46+
Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}");
47+
Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}");
48+
Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}");
6249

6350
// Update the values for the overall peak memory statistics.
6451
peakPagedMem = myProcess.PeakPagedMemorySize64;
@@ -79,27 +66,14 @@ public static void Main()
7966

8067

8168
Console.WriteLine();
82-
Console.WriteLine("Process exit code: {0}",
83-
myProcess.ExitCode);
69+
Console.WriteLine($"Process exit code: {myProcess.ExitCode}");
8470

8571
// Display peak memory statistics for the process.
86-
Console.WriteLine("Peak physical memory usage of the process: {0}",
87-
peakWorkingSet);
88-
Console.WriteLine("Peak paged memory usage of the process: {0}",
89-
peakPagedMem);
90-
Console.WriteLine("Peak virtual memory usage of the process: {0}",
91-
peakVirtualMem);
92-
93-
}
94-
finally
95-
{
96-
if (myProcess != null)
97-
{
98-
myProcess.Close();
99-
}
72+
Console.WriteLine($"Peak physical memory usage: {peakWorkingSet}");
73+
Console.WriteLine($"Peak paged memory usage: {peakPagedMem}");
74+
Console.WriteLine($"Peak virtual memory usage: {peakVirtualMem}");
10075
}
10176
}
102-
10377
}
10478
}
105-
// </Snippet1>
79+
// </Snippet1>

snippets/csharp/VS_Snippets_CLR/Process.GetProcesses_noexception/CS/processstaticget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ static void Main()
4848
}
4949
}
5050
}
51-
// </Snippet1>
51+
// </Snippet1>

snippets/csharp/VS_Snippets_CLR/Process.Start_instance/CS/processstart.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ class MyProcess
99
{
1010
public static void Main()
1111
{
12-
Process myProcess = new Process();
13-
1412
try
1513
{
16-
myProcess.StartInfo.UseShellExecute = false;
17-
// You can start any process, HelloWorld is a do-nothing example.
18-
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
19-
myProcess.StartInfo.CreateNoWindow = true;
20-
myProcess.Start();
21-
// This code assumes the process you are starting will terminate itself.
22-
// Given that is is started without a window so you cannot terminate it
23-
// on the desktop, it must terminate itself or you can do it programmatically
24-
// from this application using the Kill method.
14+
using (Process myProcess = new Process())
15+
{
16+
myProcess.StartInfo.UseShellExecute = false;
17+
// You can start any process, HelloWorld is a do-nothing example.
18+
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
19+
myProcess.StartInfo.CreateNoWindow = true;
20+
myProcess.Start();
21+
// This code assumes the process you are starting will terminate itself.
22+
// Given that is is started without a window so you cannot terminate it
23+
// on the desktop, it must terminate itself or you can do it programmatically
24+
// from this application using the Kill method.
25+
}
2526
}
2627
catch (Exception e)
2728
{
@@ -30,4 +31,4 @@ public static void Main()
3031
}
3132
}
3233
}
33-
// </Snippet1>
34+
// </Snippet1>

snippets/csharp/VS_Snippets_CLR/Process.Start_static/CS/processstartstatic.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void OpenApplication(string myFavoritesPath)
1616
// Display the contents of the favorites folder in the browser.
1717
Process.Start(myFavoritesPath);
1818
}
19-
19+
2020
// Opens urls and .html documents using Internet Explorer.
2121
void OpenWithArguments()
2222
{
@@ -135,12 +135,12 @@ static void Main(string[] args)
135135

136136
for (var i = 0; i < args.Length; i++)
137137
{
138-
Console.WriteLine("[" + i + "] = " + args[i]);
138+
Console.WriteLine($"[{i}] = {args[i]}");
139139
}
140-
140+
141141
Console.WriteLine("\nPress any key to exit");
142142
Console.ReadLine();
143143
}
144144
}
145145
}
146-
// </Snippet3>
146+
// </Snippet3>

snippets/csharp/VS_Snippets_CLR/ProcessModule/CS/processmodule.cs

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,56 @@
99

1010
class MyProcessModuleClass
1111
{
12-
public static void Main()
13-
{
14-
try
15-
{
16-
// <Snippet1>
17-
Process myProcess = new Process();
18-
// Get the process start information of notepad.
19-
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
20-
// Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
21-
myProcess.StartInfo = myProcessStartInfo;
22-
// Create a notepad.
23-
myProcess.Start();
24-
System.Threading.Thread.Sleep(1000);
25-
ProcessModule myProcessModule;
26-
// Get all the modules associated with 'myProcess'.
27-
ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
28-
Console.WriteLine("Properties of the modules associated "
29-
+"with 'notepad' are:");
30-
// Display the properties of each of the modules.
31-
for( int i=0;i<myProcessModuleCollection.Count;i++)
32-
{
33-
myProcessModule = myProcessModuleCollection[i];
34-
Console.WriteLine("The moduleName is "
35-
+myProcessModule.ModuleName);
36-
Console.WriteLine("The " +myProcessModule.ModuleName + "'s base address is: "
37-
+myProcessModule.BaseAddress);
38-
Console.WriteLine("The " +myProcessModule.ModuleName + "'s Entry point address is: "
39-
+myProcessModule.EntryPointAddress);
40-
Console.WriteLine("The " +myProcessModule.ModuleName + "'s File name is: "
41-
+myProcessModule.FileName);
42-
}
43-
// Get the main module associated with 'myProcess'.
44-
myProcessModule = myProcess.MainModule;
45-
// Display the properties of the main module.
46-
Console.WriteLine("The process's main moduleName is: "
47-
+myProcessModule.ModuleName);
48-
Console.WriteLine("The process's main module's base address is: "
49-
+myProcessModule.BaseAddress);
50-
Console.WriteLine("The process's main module's Entry point address is: "
51-
+myProcessModule.EntryPointAddress);
52-
Console.WriteLine("The process's main module's File name is: "
53-
+myProcessModule.FileName);
54-
myProcess.CloseMainWindow();
55-
// </Snippet1>
56-
}
57-
catch(Exception e)
58-
{
59-
Console.WriteLine("Exception : "+ e.Message);
60-
}
61-
}
12+
public static void Main()
13+
{
14+
try
15+
{
16+
// <Snippet1>
17+
using (Process myProcess = new Process())
18+
{
19+
// Get the process start information of notepad.
20+
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
21+
// Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
22+
myProcess.StartInfo = myProcessStartInfo;
23+
// Create a notepad.
24+
myProcess.Start();
25+
System.Threading.Thread.Sleep(1000);
26+
ProcessModule myProcessModule;
27+
// Get all the modules associated with 'myProcess'.
28+
ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
29+
Console.WriteLine("Properties of the modules associated "
30+
+ "with 'notepad' are:");
31+
// Display the properties of each of the modules.
32+
for (int i = 0; i < myProcessModuleCollection.Count; i++)
33+
{
34+
myProcessModule = myProcessModuleCollection[i];
35+
Console.WriteLine("The moduleName is "
36+
+ myProcessModule.ModuleName);
37+
Console.WriteLine("The " + myProcessModule.ModuleName + "'s base address is: "
38+
+ myProcessModule.BaseAddress);
39+
Console.WriteLine("The " + myProcessModule.ModuleName + "'s Entry point address is: "
40+
+ myProcessModule.EntryPointAddress);
41+
Console.WriteLine("The " + myProcessModule.ModuleName + "'s File name is: "
42+
+ myProcessModule.FileName);
43+
}
44+
// Get the main module associated with 'myProcess'.
45+
myProcessModule = myProcess.MainModule;
46+
// Display the properties of the main module.
47+
Console.WriteLine("The process's main moduleName is: "
48+
+ myProcessModule.ModuleName);
49+
Console.WriteLine("The process's main module's base address is: "
50+
+ myProcessModule.BaseAddress);
51+
Console.WriteLine("The process's main module's Entry point address is: "
52+
+ myProcessModule.EntryPointAddress);
53+
Console.WriteLine("The process's main module's File name is: "
54+
+ myProcessModule.FileName);
55+
myProcess.CloseMainWindow();
56+
}
57+
// </Snippet1>
58+
}
59+
catch (Exception e)
60+
{
61+
Console.WriteLine("Exception : " + e.Message);
62+
}
63+
}
6264
}
63-

0 commit comments

Comments
 (0)