本文整理汇总了C#中Power.raisePower方法的典型用法代码示例。如果您正苦于以下问题:C# Power.raisePower方法的具体用法?C# Power.raisePower怎么用?C# Power.raisePower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Power
的用法示例。
在下文中一共展示了Power.raisePower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Power power = new Power();
// initialise variables for use in while loops that
// ensure user enters correct input
int number = 0, pwr = -1;
bool validInteger = false; // if user enters invalid integer value
bool validPower = false; // if user enters invalid power value
int result;
// while user doesn't enter valid / integer value make them re-enter input
while (number < 1 || !validInteger)
{
System.Console.Write("Enter a whole to number: ");
try
{
number = int.Parse(System.Console.ReadLine());
validInteger = true;
}
catch
{
System.Console.WriteLine("Enter a valid integer!");
validInteger = false;
}
}
// run this loop until user enters a power in the correct range
while (pwr < 0 || !validPower)
{
try
{
System.Console.Write("Enter a power (>=0) to raise the number to: ");
pwr = int.Parse(System.Console.ReadLine());
validPower = true;
}
catch
{
System.Console.WriteLine("You entered an invalid power!");
validPower = false;
}
}
// calculate result using power objects method 'raisePower'
result = power.raisePower(number, pwr);
System.Console.WriteLine("The result is " + result);
}