Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions csharp/tutorials/exploration/csharp6-finished/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <SnippetUsingStatic>
using static System.Console;
// </SnippetUsingStatic>
using System.Linq;

public class Person
{
public string FirstName { get; private set; }
public string LastName { get; private set; }

// <SnippetMiddleName>
public string MiddleName { get; } = "";

public Person(string first, string middle, string last)
{
FirstName = first;
MiddleName = middle;
LastName = last;
}
// </SnippetMiddleName>

public Person(string first, string last)
{
FirstName = first;
LastName = last;
}

// <SnippetStringInterpolation>
public override string ToString() => $"{FirstName} {LastName}";
public string AllCaps() => $"{FirstName.ToUpper()} {LastName.ToUpper()}";
// </SnippetStringInterpolation>
}

public class Program
{
public static void Main()
{
// <SnippetInterpolationMain>
var p = new Person("Bill", "Wagner");
WriteLine($"The name, in all caps {p.AllCaps()}");
WriteLine($"The name is {p}");
// </SnippetInterpolationMain>
// <SnippetPhrases>
var phrase = "the quick brown fox jumps over the lazy dog";
var wordLength = from word in phrase.Split(" ") select word.Length;
var average = wordLength.Average();
WriteLine(average);
// </SnippetPhrases>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>csharp6_finished</RootNamespace>
<LangVersion>6</LangVersion>
</PropertyGroup>

</Project>
35 changes: 35 additions & 0 deletions csharp/tutorials/exploration/csharp6-starter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

public class Person
{
public string FirstName { get; private set; }
public string LastName { get; private set; }

public Person(string first, string last)
{
FirstName = first;
LastName = last;
}

public override string ToString()
{
return FirstName + " " + LastName;
}

public string AllCaps()
{
FirstName = FirstName.ToUpper();
LastName = LastName.ToUpper();
return ToString();
}
}

public class Program
{
public static void Main()
{
var p = new Person("Bill", "Wagner");
Console.WriteLine("The name, in all caps " + p.AllCaps());
Console.WriteLine("The name " + p);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>6</LangVersion>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>csharp6_starter</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@ class ProcessMonitorSample
{
public static void Main()
{

// Define variables to track the peak
// memory usage of the process.
long peakPagedMem = 0,
peakWorkingSet = 0,
peakVirtualMem = 0;

Process myProcess = null;

try
// Start the process.
using (Process myProcess = Process.Start("NotePad.exe"))
{
// Start the process.
myProcess = Process.Start("NotePad.exe");

// Display the process statistics until
// the user closes the program.
do
Expand All @@ -40,25 +35,17 @@ public static void Main()

// Display current process statistics.

Console.WriteLine("{0} -", myProcess.ToString());
Console.WriteLine($"{myProcess} -");
Console.WriteLine("-------------------------------------");

Console.WriteLine(" physical memory usage: {0}",
myProcess.WorkingSet64);
Console.WriteLine(" base priority: {0}",
myProcess.BasePriority);
Console.WriteLine(" priority class: {0}",
myProcess.PriorityClass);
Console.WriteLine(" user processor time: {0}",
myProcess.UserProcessorTime);
Console.WriteLine(" privileged processor time: {0}",
myProcess.PrivilegedProcessorTime);
Console.WriteLine(" total processor time: {0}",
myProcess.TotalProcessorTime);
Console.WriteLine(" PagedSystemMemorySize64: {0}",
myProcess.PagedSystemMemorySize64);
Console.WriteLine(" PagedMemorySize64: {0}",
myProcess.PagedMemorySize64);
Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}");
Console.WriteLine($" Base priority : {myProcess.BasePriority}");
Console.WriteLine($" Priority class : {myProcess.PriorityClass}");
Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}");
Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}");
Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}");
Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}");
Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}");

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


Console.WriteLine();
Console.WriteLine("Process exit code: {0}",
myProcess.ExitCode);
Console.WriteLine($"Process exit code: {myProcess.ExitCode}");

// Display peak memory statistics for the process.
Console.WriteLine("Peak physical memory usage of the process: {0}",
peakWorkingSet);
Console.WriteLine("Peak paged memory usage of the process: {0}",
peakPagedMem);
Console.WriteLine("Peak virtual memory usage of the process: {0}",
peakVirtualMem);

}
finally
{
if (myProcess != null)
{
myProcess.Close();
}
Console.WriteLine($"Peak physical memory usage: {peakWorkingSet}");
Console.WriteLine($"Peak paged memory usage: {peakPagedMem}");
Console.WriteLine($"Peak virtual memory usage: {peakVirtualMem}");
}
}

}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ static void Main()
}
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ class MyProcess
{
public static void Main()
{
Process myProcess = new Process();

try
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
// This code assumes the process you are starting will terminate itself.
// Given that is is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
// This code assumes the process you are starting will terminate itself.
// Given that is is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
}
}
catch (Exception e)
{
Expand All @@ -30,4 +31,4 @@ public static void Main()
}
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void OpenApplication(string myFavoritesPath)
// Display the contents of the favorites folder in the browser.
Process.Start(myFavoritesPath);
}

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
Expand Down Expand Up @@ -135,12 +135,12 @@ static void Main(string[] args)

for (var i = 0; i < args.Length; i++)
{
Console.WriteLine("[" + i + "] = " + args[i]);
Console.WriteLine($"[{i}] = {args[i]}");
}

Console.WriteLine("\nPress any key to exit");
Console.ReadLine();
}
}
}
// </Snippet3>
// </Snippet3>
103 changes: 52 additions & 51 deletions snippets/csharp/VS_Snippets_CLR/ProcessModule/CS/processmodule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,56 @@

class MyProcessModuleClass
{
public static void Main()
{
try
{
// <Snippet1>
Process myProcess = new Process();
// Get the process start information of notepad.
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
// Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
myProcess.StartInfo = myProcessStartInfo;
// Create a notepad.
myProcess.Start();
System.Threading.Thread.Sleep(1000);
ProcessModule myProcessModule;
// Get all the modules associated with 'myProcess'.
ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
Console.WriteLine("Properties of the modules associated "
+"with 'notepad' are:");
// Display the properties of each of the modules.
for( int i=0;i<myProcessModuleCollection.Count;i++)
{
myProcessModule = myProcessModuleCollection[i];
Console.WriteLine("The moduleName is "
+myProcessModule.ModuleName);
Console.WriteLine("The " +myProcessModule.ModuleName + "'s base address is: "
+myProcessModule.BaseAddress);
Console.WriteLine("The " +myProcessModule.ModuleName + "'s Entry point address is: "
+myProcessModule.EntryPointAddress);
Console.WriteLine("The " +myProcessModule.ModuleName + "'s File name is: "
+myProcessModule.FileName);
}
// Get the main module associated with 'myProcess'.
myProcessModule = myProcess.MainModule;
// Display the properties of the main module.
Console.WriteLine("The process's main moduleName is: "
+myProcessModule.ModuleName);
Console.WriteLine("The process's main module's base address is: "
+myProcessModule.BaseAddress);
Console.WriteLine("The process's main module's Entry point address is: "
+myProcessModule.EntryPointAddress);
Console.WriteLine("The process's main module's File name is: "
+myProcessModule.FileName);
myProcess.CloseMainWindow();
// </Snippet1>
}
catch(Exception e)
{
Console.WriteLine("Exception : "+ e.Message);
}
}
public static void Main()
{
try
{
// <Snippet1>
using (Process myProcess = new Process())
{
// Get the process start information of notepad.
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
// Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
myProcess.StartInfo = myProcessStartInfo;
// Create a notepad.
myProcess.Start();
System.Threading.Thread.Sleep(1000);
ProcessModule myProcessModule;
// Get all the modules associated with 'myProcess'.
ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
Console.WriteLine("Properties of the modules associated "
+ "with 'notepad' are:");
// Display the properties of each of the modules.
for (int i = 0; i < myProcessModuleCollection.Count; i++)
{
myProcessModule = myProcessModuleCollection[i];
Console.WriteLine("The moduleName is "
+ myProcessModule.ModuleName);
Console.WriteLine("The " + myProcessModule.ModuleName + "'s base address is: "
+ myProcessModule.BaseAddress);
Console.WriteLine("The " + myProcessModule.ModuleName + "'s Entry point address is: "
+ myProcessModule.EntryPointAddress);
Console.WriteLine("The " + myProcessModule.ModuleName + "'s File name is: "
+ myProcessModule.FileName);
}
// Get the main module associated with 'myProcess'.
myProcessModule = myProcess.MainModule;
// Display the properties of the main module.
Console.WriteLine("The process's main moduleName is: "
+ myProcessModule.ModuleName);
Console.WriteLine("The process's main module's base address is: "
+ myProcessModule.BaseAddress);
Console.WriteLine("The process's main module's Entry point address is: "
+ myProcessModule.EntryPointAddress);
Console.WriteLine("The process's main module's File name is: "
+ myProcessModule.FileName);
myProcess.CloseMainWindow();
}
// </Snippet1>
}
catch (Exception e)
{
Console.WriteLine("Exception : " + e.Message);
}
}
}

Loading