每當我嘗試啓動它時,它都會提出這些錯誤,並且應用程序無法運行。爲什麼?我該如何解決它,是我的編輯器? (我正在使用Microsoft Visual Studio)我的程序在打開時立即關閉
- 線程0x1688已退出,代碼爲259(0x103)。
- 線程0x470已退出,代碼爲259(0x103)。
- 線程0xc1c已退出,代碼爲259(0x103)。
- 線程0x26f0已退出,代碼爲259(0x103)。
- 線程0x2708已退出,代碼爲259(0x103)。
- 程序'[7956] ConsoleApplication1.vshost.exe'已退出,代碼爲0(0x0)。
這是代碼。
using System;
namespace Inputoftext
{
class Program
{
string str;
public void detail()
{
Console.WriteLine("Multiplication Calculator.");
Console.WriteLine("Number 1: ");
string input = Console.ReadLine();
int number;
Int32.TryParse(input, out number);
Console.WriteLine("Number 2: ");
string inputa = Console.ReadLine();
int number;
Int32.TryParse(input, out number);
}
public void calculations()
{
return input * inputa;
}
public void display()
{
Console.WriteLine();
Console.WriteLine(str);
Console.ReadKey();
}
}
class call
{
static void Main()
{
Program r = new Program();
r.detail();
r.calculations();
r.display();
Console.ReadKey();
}
}
}
順便說一句我是新來的C#,所以不要使其向複雜和IM開放的建議,以改善我的代碼。
我猜它正在啓動另一個項目,主要是因爲'控制檯。WriteLine(str);'應該給編譯器一個錯誤; 'str'永遠不會被賦予價值。檢查右邊的解決方案列表,右鍵點擊你的解決方案並點擊'Set as startup project' – Rob
Int解析可以拋出異常,使用trycatch – meda
這段代碼永遠不能編譯。請發佈導致您遇到問題的真實代碼。 –