我是新來的,我按照指示一步一步,但由於某種原因不斷得到stackoverflowexception。我究竟做錯了什麼?得到一個stackoverflowexception並不知道爲什麼。任何人都可以幫忙嗎?
using System;
using System.Collections.Generic;
using System.Linq;
namespace assignment3
{
class changeValue
{
//Create a class called changeValue that declares 2 integer class variables: value1 and
// value2. These should be declared as public and you should not use automatic properties
// to declare them.
public int value1
{
get
{
return value1;
}//end get
set
{
value1 = value;
}//end set
}
public int value2
{
get
{
return value2;
}//end get
set
{
value2 = value;
}//end set
}
public changeValue(int val1, int val2)
{
//here is the constructor where you code the if statements
int value1 = val1;
int value2 = val2;
if (value1 > 5)
{
value1 = val1;
}
if (val1 <= 5)
{
value1 = (val1+val2);
}
if (val2 < 10)
{
value2 = (val2 * val2 + 5);
}
if (val2 >= 10)
{
value2 = val2;
}
}
public void printit()
{
//here is the printit method used to print the results
Console.WriteLine("The calculated value is:" + (value1 * value2));
}
}
class assignment3
{
public static void Main(string[] args)
{
//declare the local val1 and val2 integer variables
int val1;
int val2;
//prompt the user for input of two integers
//don’t forget to convert from the string input to integer
Console.Write("Enter an integer value: "); //obtain user input
val1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a second integer value: "); //obtain user input
val2 = Convert.ToInt32(Console.ReadLine());
//instantiate a changeValue object here
changeValue myValue = new changeValue(val1,val2);
myValue.printit();//call the object method printit here
}
}
}
爲'value1'返回'value1',這就要求'value1'吸氣,返回吸氣'value1'它調用'value1'的getter ... – 2014-09-12 13:51:24
在不到三分鐘內六個答案...哇。 – 2014-09-12 13:53:15
10分鐘內最多答案的記錄是多少。 – DidIReallyWriteThat 2014-09-12 13:54:19