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
108 changes: 54 additions & 54 deletions snippets/csharp/VS_Snippets_CLR/math.max/CS/max.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
//<snippet1>
// This example demonstrates Math.Max()
// This example demonstrates Math.Max()
using System;

class Sample
{
public static void Main()
{
string str = "{0}: The greater of {1,3} and {2,3} is {3}.";
string nl = Environment.NewLine;

byte xByte1 = 1, xByte2 = 51;
short xShort1 = -2, xShort2 = 52;
int xInt1 = -3, xInt2 = 53;
long xLong1 = -4, xLong2 = 54;
float xSingle1 = 5.0f, xSingle2 = 55.0f;
double xDouble1 = 6.0, xDouble2 = 56.0;
Decimal xDecimal1 = 7m, xDecimal2 = 57m;

// The following types are not CLS-compliant.
sbyte xSbyte1 = 101, xSbyte2 = 111;
ushort xUshort1 = 102, xUshort2 = 112;
uint xUint1 = 103, xUint2 = 113;
ulong xUlong1 = 104, xUlong2 = 114;

Console.WriteLine("{0}Display the greater of two values:{0}", nl);
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Max(xByte1, xByte2));
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Max(xShort1, xShort2));
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Max(xInt1, xInt2));
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Max(xLong1, xLong2));
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2));
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2));
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2));
//
Console.WriteLine("{0}The following types are not CLS-compliant.{0}", nl);
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Max(xSbyte1, xSbyte2));
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Max(xUshort1, xUshort2));
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2));
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2));
//<snippet1>
string str = "{0}: The greater of {1,3} and {2,3} is {3}.";

byte xByte1 = 1, xByte2 = 51;
short xShort1 = -2, xShort2 = 52;
int xInt1 = -3, xInt2 = 53;
long xLong1 = -4, xLong2 = 54;
float xSingle1 = 5.0f, xSingle2 = 55.0f;
double xDouble1 = 6.0, xDouble2 = 56.0;
Decimal xDecimal1 = 7m, xDecimal2 = 57m;

// The following types are not CLS-compliant.
sbyte xSbyte1 = 101, xSbyte2 = 111;
ushort xUshort1 = 102, xUshort2 = 112;
uint xUint1 = 103, xUint2 = 113;
ulong xUlong1 = 104, xUlong2 = 114;

Console.WriteLine("Display the greater of two values:\n");
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Max(xByte1, xByte2));
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Max(xShort1, xShort2));
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Max(xInt1, xInt2));
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Max(xLong1, xLong2));
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2));
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2));
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2));

Console.WriteLine("\nThe following types are not CLS-compliant.\n");
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Max(xSbyte1, xSbyte2));
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Max(xUshort1, xUshort2));
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2));
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2));

/*
This example produces the following results:

Display the greater of two values:

Byte : The greater of 1 and 51 is 51.
Int16 : The greater of -2 and 52 is 52.
Int32 : The greater of -3 and 53 is 53.
Int64 : The greater of -4 and 54 is 54.
Single : The greater of 5 and 55 is 55.
Double : The greater of 6 and 56 is 56.
Decimal: The greater of 7 and 57 is 57.

(The following types are not CLS-compliant.)

SByte : The greater of 101 and 111 is 111.
UInt16 : The greater of 102 and 112 is 112.
UInt32 : The greater of 103 and 113 is 113.
UInt64 : The greater of 104 and 114 is 114.
*/
//</snippet1>
}
}
/*
This example produces the following results:

Display the greater of two values:

Byte : The greater of 1 and 51 is 51.
Int16 : The greater of -2 and 52 is 52.
Int32 : The greater of -3 and 53 is 53.
Int64 : The greater of -4 and 54 is 54.
Single : The greater of 5 and 55 is 55.
Double : The greater of 6 and 56 is 56.
Decimal: The greater of 7 and 57 is 57.

(The following types are not CLS-compliant.)

SByte : The greater of 101 and 111 is 111.
UInt16 : The greater of 102 and 112 is 112.
UInt32 : The greater of 103 and 113 is 113.
UInt64 : The greater of 104 and 114 is 114.
*/
//</snippet1>
108 changes: 54 additions & 54 deletions snippets/csharp/VS_Snippets_CLR/math.min/CS/min.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
//<snippet1>
// This example demonstrates Math.Min()
// This example demonstrates Math.Min()
using System;

class Sample
{
public static void Main()
{
string str = "{0}: The lesser of {1,3} and {2,3} is {3}.";
string nl = Environment.NewLine;

byte xByte1 = 1, xByte2 = 51;
short xShort1 = -2, xShort2 = 52;
int xInt1 = -3, xInt2 = 53;
long xLong1 = -4, xLong2 = 54;
float xSingle1 = 5.0f, xSingle2 = 55.0f;
double xDouble1 = 6.0, xDouble2 = 56.0;
Decimal xDecimal1 = 7m, xDecimal2 = 57m;

// The following types are not CLS-compliant.
sbyte xSbyte1 = 101, xSbyte2 = 111;
ushort xUshort1 = 102, xUshort2 = 112;
uint xUint1 = 103, xUint2 = 113;
ulong xUlong1 = 104, xUlong2 = 114;

Console.WriteLine("{0}Display the lesser of two values:{0}", nl);
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Min(xByte1, xByte2));
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Min(xShort1, xShort2));
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Min(xInt1, xInt2));
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Min(xLong1, xLong2));
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2));
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2));
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2));
//
Console.WriteLine("{0}The following types are not CLS-compliant:{0}", nl);
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));
//<snippet1>
string str = "{0}: The lesser of {1,3} and {2,3} is {3}.";

byte xByte1 = 1, xByte2 = 51;
short xShort1 = -2, xShort2 = 52;
int xInt1 = -3, xInt2 = 53;
long xLong1 = -4, xLong2 = 54;
float xSingle1 = 5.0f, xSingle2 = 55.0f;
double xDouble1 = 6.0, xDouble2 = 56.0;
Decimal xDecimal1 = 7m, xDecimal2 = 57m;

// The following types are not CLS-compliant.
sbyte xSbyte1 = 101, xSbyte2 = 111;
ushort xUshort1 = 102, xUshort2 = 112;
uint xUint1 = 103, xUint2 = 113;
ulong xUlong1 = 104, xUlong2 = 114;

Console.WriteLine("Display the lesser of two values:\n");
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Min(xByte1, xByte2));
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Min(xShort1, xShort2));
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Min(xInt1, xInt2));
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Min(xLong1, xLong2));
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2));
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2));
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2));

Console.WriteLine("\nThe following types are not CLS-compliant:\n");
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));

/*
This example produces the following results:

Display the lesser of two values:

Byte : The lesser of 1 and 51 is 1.
Int16 : The lesser of -2 and 52 is -2.
Int32 : The lesser of -3 and 53 is -3.
Int64 : The lesser of -4 and 54 is -4.
Single : The lesser of 5 and 55 is 5.
Double : The lesser of 6 and 56 is 6.
Decimal: The lesser of 7 and 57 is 7.

The following types are not CLS-compliant:

SByte : The lesser of 101 and 111 is 101.
UInt16 : The lesser of 102 and 112 is 102.
UInt32 : The lesser of 103 and 113 is 103.
UInt64 : The lesser of 104 and 114 is 104.
*/
//</snippet1>
}
}
/*
This example produces the following results:

Display the lesser of two values:

Byte : The lesser of 1 and 51 is 1.
Int16 : The lesser of -2 and 52 is -2.
Int32 : The lesser of -3 and 53 is -3.
Int64 : The lesser of -4 and 54 is -4.
Single : The lesser of 5 and 55 is 5.
Double : The lesser of 6 and 56 is 6.
Decimal: The lesser of 7 and 57 is 7.

The following types are not CLS-compliant:

SByte : The lesser of 101 and 111 is 101.
UInt16 : The lesser of 102 and 112 is 102.
UInt32 : The lesser of 103 and 113 is 103.
UInt64 : The lesser of 104 and 114 is 104.
*/
//</snippet1>
21 changes: 10 additions & 11 deletions snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/Abs1.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// <Snippet1>
using System;
using System;

public class Example
{
public static void Main()
{
// <Snippet1>
decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -19.69M,
Decimal.MinValue };
foreach (decimal value in decimals)
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");

// The example displays the following output:
// Abs(79228162514264337593543950335) = 79228162514264337593543950335
// Abs(12.45) = 12.45
// Abs(0) = 0
// Abs(-19.69) = 19.69
// Abs(-79228162514264337593543950335) = 79228162514264337593543950335
// </Snippet1>
}
}
// The example displays the following output:
// Abs(79228162514264337593543950335) = 79228162514264337593543950335
// Abs(12.45) = 12.45
// Abs(0) = 0
// Abs(-19.69) = 19.69
// Abs(-79228162514264337593543950335) = 79228162514264337593543950335
// </Snippet1>

25 changes: 13 additions & 12 deletions snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/abs2.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// <Snippet2>
using System;
using System;

public class Example
{
public static void Main()
{
// <Snippet2>
double[] doubles = { Double.MaxValue, 16.354e-17, 15.098123, 0,
-19.069713, -15.058e18, Double.MinValue };
foreach (double value in doubles)
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");

// The example displays the following output:
// Abs(1.79769313486232E+308) = 1.79769313486232E+308
// Abs(1.6354E-16) = 1.6354E-16
// Abs(15.098123) = 15.098123
// Abs(0) = 0
// Abs(-19.069713) = 19.069713
// Abs(-1.5058E+19) = 1.5058E+19
// Abs(-1.79769313486232E+308) = 1.79769313486232E+308
// </Snippet2>
}
}
// The example displays the following output:
// Abs(1.79769313486232E+308) = 1.79769313486232E+308
// Abs(1.6354E-16) = 1.6354E-16
// Abs(15.098123) = 15.098123
// Abs(0) = 0
// Abs(-19.069713) = 19.069713
// Abs(-1.5058E+19) = 1.5058E+19
// Abs(-1.79769313486232E+308) = 1.79769313486232E+308
// </Snippet2>

21 changes: 11 additions & 10 deletions snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/abs3.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// <Snippet3>
using System;
using System;

public class Example
{
public static void Main()
{
// <Snippet3>
short[] values = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue };
foreach (short value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}

// The example displays the following output:
// Abs(32767) = 32767
// Abs(10328) = 10328
// Abs(0) = 0
// Abs(-1476) = 1476
// Unable to calculate the absolute value of -32768.
// </Snippet3>
}
}
// The example displays the following output:
// Abs(32767) = 32767
// Abs(10328) = 10328
// Abs(0) = 0
// Abs(-1476) = 1476
// Unable to calculate the absolute value of -32768.
// </Snippet3>
21 changes: 11 additions & 10 deletions snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/abs4.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// <Snippet4>
using System;
using System;

public class Example
{
public static void Main()
{
// <Snippet4>
int[] values = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue };
foreach (int value in values)
{
try {
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
}
catch (OverflowException) {
Console.WriteLine("Unable to calculate the absolute value of {0}.",
value);
}
}

// The example displays the following output:
// Abs(2147483647) = 2147483647
// Abs(16921) = 16921
// Abs(0) = 0
// Abs(-804128) = 804128
// Unable to calculate the absolute value of -2147483648.
// </Snippet4>
}
}
// The example displays the following output:
// Abs(2147483647) = 2147483647
// Abs(16921) = 16921
// Abs(0) = 0
// Abs(-804128) = 804128
// Unable to calculate the absolute value of -2147483648.
// </Snippet4>
Loading