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
4 changes: 2 additions & 2 deletions machine-learning/tutorials/TransferLearningTF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public static void ClassifyImages(MLContext mlContext, string dataLocation, stri

// Read the image_list.tsv file and add the filepath to the image file name
// before loading into ImageData
// <SnippetReadFromTSV>
// <SnippetCallReadFromTSV>
var imageData = ReadFromTsv(dataLocation, imagesFolder);
var imageDataView = mlContext.Data.LoadFromEnumerable<ImageData>(imageData);
// </SnippetReadFromTSV>
// </SnippetCallReadFromTSV>

// <SnippetPredict>
var predictions = model.Transform(imageDataView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public static void Main()
// Chicago 62
// New York 67
// San Francisco 59
// Seattle 58
// </Snippet16>
18 changes: 18 additions & 0 deletions snippets/standard/base-types/string-practices/cs/formattable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;

class Program
{
static void Main()
{
Decimal value = 126.03m;
FormattableString amount = $"The amount is {value:C}";
Console.WriteLine(amount.ToString());
Console.WriteLine(amount.ToString(new CultureInfo("fr-FR")));
Console.WriteLine(FormattableString.Invariant(amount));
}
}
// The example displays the following output:
// The amount is $126.03
// The amount is 126,03 €
// The amount is ¤126.03
18 changes: 18 additions & 0 deletions snippets/standard/base-types/string-practices/cs/tostring.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;

class Program
{
static void Main(string[] args)
{
// <Snippet1>
string concat1 = "The amount is " + 126.03 + ".";
Console.WriteLine(concat1);
// </Snippet1>

// <Snippet2>
string concat2 = "The amount is " + 126.03.ToString(CultureInfo.InvariantCulture) + ".";
Console.WriteLine(concat2);
// </Snippet2>
}
}
15 changes: 15 additions & 0 deletions snippets/standard/base-types/string-practices/vb/formattable.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Imports System.Globalization

Module Program
Sub Main()
Dim value As Decimal = 126.03
Dim amount As FormattableString = $"The amount is {value:C}"
Console.WriteLine(amount.ToString())
Console.WriteLine(amount.ToString(new CultureInfo("fr-FR")))
Console.WriteLine(FormattableString.Invariant(amount))
End Sub
End Module
' The example displays the following output:
' The amount is $126.03
' The amount is 126,03 €
' The amount is ¤126.03
29 changes: 29 additions & 0 deletions snippets/standard/interop/pinvoke/enumwindows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
public static class Program
{
// Define a delegate that corresponds to the unmanaged function.
private delegate bool EnumWC(IntPtr hwnd, IntPtr lParam);

// Import user32.dll (containing the function we need) and define
// the method corresponding to the native function.
[DllImport("user32.dll")]
private static extern int EnumWindows(EnumWC lpEnumFunc, IntPtr lParam);

// Define the implementation of the delegate; here, we simply output the window handle.
private static bool OutputWindow(IntPtr hwnd, IntPtr lParam)
{
Console.WriteLine(hwnd.ToInt64());
return true;
}

public static void Main(string[] args)
{
// Invoke the method; note the delegate as a first parameter.
EnumWindows(OutputWindow, IntPtr.Zero);
}
}
}
51 changes: 51 additions & 0 deletions snippets/standard/interop/pinvoke/ftw-linux.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Runtime.InteropServices;

namespace PInvokeSamples
{
public static class Program
{
// Define a delegate that has the same signature as the native function.
private delegate int DirClbk(string fName, StatClass stat, int typeFlag);

// Import the libc and define the method to represent the native function.
[DllImport("libc.so.6")]
private static extern int ftw(string dirpath, DirClbk cl, int descriptors);

// Implement the above DirClbk delegate;
// this one just prints out the filename that is passed to it.
private static int DisplayEntry(string fName, StatClass stat, int typeFlag)
{
Console.WriteLine(fName);
return 0;
}

public static void Main(string[] args)
{
// Call the native function.
// Note the second parameter which represents the delegate (callback).
ftw(".", DisplayEntry, 10);
}
}

// The native callback takes a pointer to a struct. The below class
// represents that struct in managed code. You can find more information
// about this in the section on marshalling below.
[StructLayout(LayoutKind.Sequential)]
public class StatClass
{
public uint DeviceID;
public uint InodeNumber;
public uint Mode;
public uint HardLinks;
public uint UserID;
public uint GroupID;
public uint SpecialDeviceID;
public ulong Size;
public ulong BlockSize;
public uint Blocks;
public long TimeLastAccess;
public long TimeLastModification;
public long TimeLastStatusChange;
}
}
50 changes: 50 additions & 0 deletions snippets/standard/interop/pinvoke/ftw-macos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Runtime.InteropServices;

namespace PInvokeSamples
{
public static class Program
{
// Define a delegate that has the same signature as the native function.
private delegate int DirClbk(string fName, StatClass stat, int typeFlag);

// Import the libc and define the method to represent the native function.
[DllImport("libSystem.dylib")]
private static extern int ftw(string dirpath, DirClbk cl, int descriptors);

// Implement the above DirClbk delegate;
// this one just prints out the filename that is passed to it.
private static int DisplayEntry(string fName, StatClass stat, int typeFlag)
{
Console.WriteLine(fName);
return 0;
}

public static void Main(string[] args)
{
// Call the native function.
// Note the second parameter which represents the delegate (callback).
ftw(".", DisplayEntry, 10);
}
}

// The native callback takes a pointer to a struct. The below class
// represents that struct in managed code.
[StructLayout(LayoutKind.Sequential)]
public class StatClass
{
public uint DeviceID;
public uint InodeNumber;
public uint Mode;
public uint HardLinks;
public uint UserID;
public uint GroupID;
public uint SpecialDeviceID;
public ulong Size;
public ulong BlockSize;
public uint Blocks;
public long TimeLastAccess;
public long TimeLastModification;
public long TimeLastStatusChange;
}
}
20 changes: 20 additions & 0 deletions snippets/standard/interop/pinvoke/getpid-linux.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;

namespace PInvokeSamples
{
public static class Program
{
// Import the libc shared library and define the method
// corresponding to the native function.
[DllImport("libc.so.6")]
private static extern int getpid();

public static void Main(string[] args)
{
// Invoke the function and get the process ID.
int pid = getpid();
Console.WriteLine(pid);
}
}
}
20 changes: 20 additions & 0 deletions snippets/standard/interop/pinvoke/getpid-macos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;

namespace PInvokeSamples
{
public static class Program
{
// Import the libSystem shared library and define the method
// corresponding to the native function.
[DllImport("libSystem.dylib")]
private static extern int getpid();

public static void Main(string[] args)
{
// Invoke the function and get the process ID.
int pid = getpid();
Console.WriteLine(pid);
}
}
}
16 changes: 16 additions & 0 deletions snippets/standard/interop/pinvoke/messagebox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.InteropServices;

public class Program
{
// Import user32.dll (containing the function we need) and define
// the method corresponding to the native function.
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);

public static void Main(string[] args)
{
// Invoke the function as a regular managed method.
MessageBox(IntPtr.Zero, "Command-line message box", "Attention!", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ End Module
' Chicago 62
' New York 67
' San Francisco 59
' Seattle 58
' </Snippet16>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Imports System.IO

Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.FileIO

Class Class00ad6fbd924e4a49af32d505fe69ea32
' 00ad6fbd-924e-4a49-af32-d505fe69ea32
Expand Down Expand Up @@ -1071,4 +1072,32 @@ Class Class7bb0d83e875a4b158935bdc24e71ef98

End Class

Class Classe02587a6e85494d7f9392beae2c7f3903
'02587a6e-8549-4d7f-9392-beae2c7f3903
' My.Computer.FileSystem.CopyDirectory Method
Public Sub Method91()
' <snippet91>
My.Computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2")
' </snippet91>
End Sub
End Class

Class Classe664cd9b1a9174Ffc96ed789c60582205
' 664cd9b1-a917-4ffc-96ed-789c60582205
' My.Computer.FileSystem.CopyDirectory Method
Public Sub Method92()
' <snippet92>
My.Computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2", UIOption.AllDialogs)
' </snippet92>
End Sub
End Class

Class Classe9df56b2b8eb34f9ba184c2bb529eeaa7
' 9df56b2b-8eb3-4f9b-a184-c2bb529eeaa7
' My.Computer.FileSystem.CopyDirectory Method
Public Sub Method93()
' <snippet93>
My.Computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2", UIOption.AllDialogs, UICancelOption.DoNothing)
' </snippet93>
End Sub
End Class