-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Math.xml samples -- updating for Try .NET #1875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,63 @@ | ||
//<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}."; | ||
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)); | ||
|
||
/* | ||
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,64 @@ | ||
//<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}."; | ||
string nl = Environment.NewLine; | ||
WilliamAntonRohm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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)); | ||
|
||
// | ||
WilliamAntonRohm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)); | ||
|
||
/* | ||
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> |
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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may check if there are other places where string interpolation can be used.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This set of changes is optional, but highly recommended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This instance is fixed -- looking for others now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BillWagner, @Youssef1313 -- there are 13 more such constructs in this set of example files; working on them. |
||||||
|
||||||
// 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> | ||||||
|
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)); | ||
|
||
// 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> | ||
|
Uh oh!
There was an error while loading. Please reload this page.