在Visual C#2010 Express中,當按下ctr + F7以下代碼時,爲什麼控制檯不能打開?我在同一個項目中有幾個.cs文件,但我只想執行這個。在Visual C#2010 Express中按ctrl + F7時控制檯未打開?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
namespace ConsoleRead
{
protected class consoleread
{
public void GetPortName()
{
string[] sPorts = SerialPort.GetPortNames();
foreach (string port in sPorts)
{
var serialPort = new SerialPort();
serialPort.PortName = port;
serialPort.Open();
serialPort.WriteLine("ATI");
var message = Console.ReadLine();
}
}
}
}
非常感謝提前!
非常感謝,您是否建議使用Main方法替換GetPortName方法,就像您發佈的MSDN示例中一樣? clr + F7只執行Main方法嗎? – 2012-08-14 10:28:06
用更多的細節編輯我的答案 – 2012-08-14 10:35:57
非常感謝!我在我的啓動對象中沒有設置。我怎樣才能使它成爲主要方法? – 2012-08-14 10:40:25