感谢Queston的回答:)
我在一个类中创建了一个包含多个方法的代码,但是当我尝试运行它时,它说
预期的类,委托,枚举,接口或结构
关于两种不是主要方法的方法。我读了一遍,发现有人有同样的问题,案例是这些方法不在课堂上。但无法弄清楚如何解决这个问题。有小费吗?
PS:我对编码很新;)
IsEnabled=false
}
答案 0 :(得分:1)
工作版:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app='app' ng-controller='myController'>
<ion-list>
<ion-item ng-class="{red : somearray.indexOf($index) > -1}" ng-repeat="todo in todos" class="item" >
<div>
<button class="button button-block button-dark" ng-click="addNewForm($index)">
{{todo.title}}
</button>
{{$index}}
</div>
</ion-item>
</ion-list>
</div>
public static void Main(string[] args)
{
string answer;
Console.WriteLine("Would you like to divide or multiply? Type your choice.");
while (true)
{
answer = (Console.ReadLine());
if (answer == "multiply")
{
MultiplyingMethod();
break;
}
else if (answer == "divide")
{
DividingMethod();
break;
}
else
{
Console.WriteLine("Please type multiply or divide.");
}
}
}
public static void DividingMethod()
{
Console.Write("Enter a number to be divided");
double num01 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number to divide by");
double num02 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num01 + " divided by " + num02 + " is equal to " + num01/num02);
Console.WriteLine("");
Console.ReadKey();
}
public static void MultiplyingMethod()
{
double num01;
double num02;
Console.Write("Enter a number to be multiplied");
num01 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a numeber to multiply by");
num02 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num01 + " multiplied by " + num02 + " equals " + num01*num02);
Console.WriteLine("");
Console.ReadKey();
}
等参数而非MultiplyingMethod();
的方法。那是没有效的C#MultiplyingMethod;
。它会使你的代码变得混乱。看看loops 答案 1 :(得分:0)
您应该使用()调用方法。
Write MultiplyingMethod();而不是MultiplyingMethod();和 DividingMethod();而不是DividingMethod;
public static void Main(string[] args)
{
string answer;
Console.WriteLine("Would you like to divide or multiply? Type your choice.");
Start:
answer = (Console.ReadLine());
if (answer == "multiply")
{
MultiplyingMethod();
}
else if (answer == "divide")
{
DividingMethod();
}
else
{
Console.WriteLine("Please type multiply or divide.");
goto Start;
}
}
public static void DividingMethod()
{
double num01;
double num02;
Console.Write("Enter a number to be divided");
num01 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a number to divide by");
num02 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num01 + " divided by " + num02 + " is equal to " + num01 / num02);
Console.WriteLine("");
Console.ReadKey();
}
public static void MultiplyingMethod()
{
double num01;
double num02;
Console.Write("Enter a number to be multiplied");
num01 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a numeber to multiply by");
num02 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num01 + " multiplied by " + num02 + " equals " + num01 * num02);
Console.WriteLine("");
Console.ReadKey();
}
另外,永远不要使用goto,这不好!
答案 2 :(得分:0)
此代码存在以下几个问题:
DividingMethod;
变为DividingMethod();
if(answer ==“multiply”) { MultiplyingMethod; } { 否则如果(回答==“除”) { DividingMethod; } }
应该是:
if (answer == "multiply")
{
MultiplyingMethod();
}
else if (answer == "divide")
{
DividingMethod();
}