using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NonExtensionExample {
class NonExtensionExample {
static void Main(string[] args) {
Console.WriteLine("NonExtensionExample.cs");
Console.Write("Enter a number between 1 and 10 ==> ");
int i = int.Parse(Console.ReadLine());
Console.WriteLine("The value is {0} ",
CheckExtensions.CheckRange(i, 1, 10) ? i.ToString() : "out of range");
Console.Write("Enter of these values {CA | NY | TX | FL | NC} ==> ");
String state = Console.ReadLine().ToUpper();
Console.WriteLine("The state is {0} ",
CheckExtensions.CheckValues(state, "CA", "NY", "TX", "FL", "NC") ? state : " not in the list");
Console.WriteLine("End of tester");
Console.ReadLine();
}
}
///
/// Class that contains commonly used "check" methods to
/// perform DDS-like checking of data types.
///
public static class CheckExtensions {
///
/// Method that performs range checking feature for integer data.
///
/// The integer value to check.
/// The inclusive low value of the range to check.
/// The inclusive high value of the range to check.
/// Boolean indicating whether or not the value is within the range.
public static bool CheckRange(int number,
int lowValue,
int highValue) {
if ((number >= lowValue) && (number <= highValue)) { return true; }
else { return false; }
}
///
/// Method that checks to see if a string value is in a list of values.
///
/// The string value to check.
/// A comma-delimited list of string values that are the
/// valid values.
/// Boolean indicating whether or not the value is in the list.
public static bool CheckValues(String testValue,
params String[] values) {
if (values.Contains(testValue)) { return true; }
else { return false; }
}
}
}