Max/Min for int and double values : int « Data Types « C# / C Sharp






Max/Min for int and double values

    
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Newtonsoft.Json.Utilities
{
  internal class MathUtils
  {


    public static int? Min(int? val1, int? val2)
    {
      if (val1 == null)
        return val2;
      if (val2 == null)
        return val1;

      return Math.Min(val1.Value, val2.Value);
    }

    public static int? Max(int? val1, int? val2)
    {
      if (val1 == null)
        return val2;
      if (val2 == null)
        return val1;

      return Math.Max(val1.Value, val2.Value);
    }

    public static double? Min(double? val1, double? val2)
    {
      if (val1 == null)
        return val2;
      if (val2 == null)
        return val1;

      return Math.Min(val1.Value, val2.Value);
    }

    public static double? Max(double? val1, double? val2)
    {
      if (val1 == null)
        return val2;
      if (val2 == null)
        return val1;

      return Math.Max(val1.Value, val2.Value);
    }
  }
}

   
    
    
    
  








Related examples in the same category

1.Assign value to int variable
2.Call methods from primitive data types
3.Calculating the product of three integers.
4.Comparing integers using if statements, equality operators, and relational operators.
5.demonstrates variablesdemonstrates variables
6.Assing value to int valueAssing value to int value
7.Calculate: int and doubleCalculate: int and double
8.Size of int, double, char and boolSize of int, double, char and bool
9.displays a conversion table of Fahrenheit to Celsiusdisplays a conversion  
   table of Fahrenheit to Celsius
10.Some Operator on int
11.Using Integers
12.Using Variables
13.Convert string value to integer by using the int.TryParse
14.Use CultureInfo int ToString method
15.Integer OverFlow
16.Catch OverflowException Exception
17.Do calculation with int variable
18.Format int in Console.WriteLine
19.Use CultureInfo in int.ToString method
20.Use #, % and in int format
21.int based Fahrenheit and Celsius (Centigrade) Scales
22.int array property
23.Parse int value
24.The precision specifier controls the number of significant digits or zeros to the right of a decimal:
25.Int value To Hex char
26.Get the digit-length of an int value
27.Read sync safe int 32
28.Write Synch safe Int32
29.Calculate average for a list of integer values with params int[] values
30.Int extension Convert integer to boolean, is it even, is it positive
31.Converts an integer into a roman numeral.
32.Get Ordinal
33.Output with x8 format
34.Int32.MaxValue and Int32.MinValue
35.Convert Bytes To UInt
36.Compress UInt
37.Decompress UInt
38.Write Compressed UInt32
39.Read Compressed UInt32
40.Compress Int
41.Is even