如何从Windows窗体访问和运行控制台应用程序,该窗体是同一项目的一部分.我有一个Windows窗体和一个控制台应用程序.我认为我可以发布控制台应用程序然后使用,Process.Start(path to console app)但这不是我想要的.我想Main在我的表单项目中访问和使用控制台应用程序的方法.只需单击一个按钮即可运行此方法.
这会产生以下错误.
InvalidOperationException未处理当任一应用程序没有控制台或从文件重定向控制台输入时,无法读取键.试试Console.Read.
private void buttonApplication_Click(object sender, EventArgs e)
{
Ch15Extra_2.Program.Main();
}
Run Code Online (Sandbox Code Playgroud)
这是方法.
ConsoleApp:
namespace Ch15Extra_2
{
public class Program
{
public static void Main()
{
Console.WriteLine("Here the app is running");
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
Form1中:
private void buttonApplication_Click(object sender, EventArgs e) { }
Run Code Online (Sandbox Code Playgroud) 我有一个HashSet当我使用Add该集合的方法时,没有添加任何内容.输出仍然2, 3, 5, 7, 11, 13是,输出.Count是6.
这是一个错误还是我在这里做错了什么?
namespace AllerDiz
{
class MainClass
{
public static void Main (string[] args)
{
HashSet<int> smallPrimeNumbers = new HashSet<int> { 2, 3, 5, 7, 11, 13 };
smallPrimeNumbers.Add (3);
smallPrimeNumbers.Add (5);
smallPrimeNumbers.Add (7);
Console.WriteLine ("{0}", smallPrimeNumbers.Count);
foreach(int val in smallPrimeNumbers)
{
Console.WriteLine ("HashSet Value= {0}", val);
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 
为什么这样做?
private void button1_Click(object sender, EventArgs e)
{
if (!checkBox1.Checked)
{
MessageBox.Show("The box is not checked!");
}
if (checkBox1.Checked == true)
{
if (label1.BackColor == Color.Red)
{
label1.BackColor = Color.Blue;
}
else
{
label1.BackColor = Color.Red;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这不是吗?
private void button1_Click(object sender, EventArgs e)
{
if (!checkBox1.Checked)
{
MessageBox.Show("The box is not checked!");
}
if (checkBox1.Checked == true)
{
if (label1.BackColor == Color.Red)
{
label1.BackColor = Color.Blue;
}
if (label1.BackColor == Color.Blue)
{
label1.BackColor = Color.Red;
}
} …Run Code Online (Sandbox Code Playgroud) 我一直在学习 python,但我的一个系统上的 Python 交互式 shell 有问题。它在每次 python 交互模式启动时运行一个脚本(不带参数)。我不知道在哪里寻找执行此操作的进程,我在这个系统上编写了很多小脚本,并且我可以看到什么脚本在乱搞,
当我这样做时:
user@Host ~/Python Scripts> python
Run Code Online (Sandbox Code Playgroud)
我得到:
Python 3.4.2 (default, Feb 21 2015, 22:19:02)
[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
# ! / u s r / b i n / e n v p y t h o n
finished
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "/usr/local/opt/python-3.4.2/lib/python3.4/site.py", line 396, in register_readline
import rlcompleter
File "/usr/local/opt/python-3.4.2/lib/python3.4/rlcompleter.py", line 161, in …Run Code Online (Sandbox Code Playgroud) 我收到了拒绝访问权限的异常.我怎样才能解决这个问题?
这是一个例外:
System.UnauthorizedAccessException未处理HResult = -2147024891 Message =拒绝访问路径'c:\ message.txt'.
来源= mscorlib程序
这是代码:
public static void WriteToFile(string s)
{
fs = new FileStream("c:\\message.txt",
FileMode.Append, FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine(s);
sw.Flush();
sw.Close();
fs.Close();
}
Run Code Online (Sandbox Code Playgroud)
编辑:如果我以管理员身份运行vs2012,它是否有效,但有没有办法或理由以普通用户身份执行?
这有效:
public static void WriteToFile(string s)
{
fs = new FileStream(@"C:\Users\KristjanBEstur\Documents\message.txt",
FileMode.Append, FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine(s);
sw.Flush();
sw.Close();
fs.Close();
File.Delete(@"C:\Users\KristjanBEstur\Documents\message.txt");
}
Run Code Online (Sandbox Code Playgroud) 我已经在Linux中使用Pydev/Eclipse好几天了,但是在安装了一些新软件(一堆)后,我再也不能在编辑器中输入" ( ")了.
任何想法可能是什么问题?
它与此有关,对于noobness抱歉,但我仍然无法理解我正在学习的所有软件:

这是什么以及如何摆脱它?:

以下是我认为相关的错误消息:
A conflict occurred for CTRL+SHIFT+T:
Binding(CTRL+SHIFT+T,
ParameterizedCommand(Command(org.python.pydev.editor.actions.pyShowBrowser,Python Show Global Tokens (Editor),
Python Show Global Tokens (Editor),
Category(org.python.pydev.ui.category.source,PyDev - Editor,PyDev editor category,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@5644fc26,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
org.python.pydev.ui.editor.scope,,,system)
Binding(CTRL+SHIFT+T,
ParameterizedCommand(Command(com.python.pydev.analysis.actions.pyGlobalsBrowserWorkbench,Python Show Global Tokens (Global),
Python Show Global Tokens (Global),
Category(org.python.pydev.ui.category.source,PyDev - Editor,PyDev editor category,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4b064f09,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
com.python.pydev.contexts.window,,,system)
Binding(CTRL+SHIFT+T,
ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type,
Open a type in a Java editor,
Category(org.eclipse.ui.category.navigate,Navigate,null,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@b2efe5a,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
org.eclipse.ui.contexts.window,,,system)
Run Code Online (Sandbox Code Playgroud) 我有这个代码,但它不起作用.我尝试了几个不同的版本,但没有任何工作.我是新手,但仍然不懂一切.
OpenFileDialog filedialog = new OpenFileDialog();
private void button3_Click(object sender, EventArgs e)
{
filedialog.ShowDialog();
filedialog.FileOk += filedialog_FileOk;
}
void filedialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
using (StreamReader myStream = new StreamReader(filedialog.FileName))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = myStream.ReadLine()) != null)
{
listBox1.Items.Add(line);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这个编辑器需要很多纯文本.
如何在C#中打印文本文件?在控制台应用程序中.
这就是我发现的:msdn sample和这个stackoverflow:answer是msdn示例
链接中的代码适用于Windows窗体应用程序,并且不适用于控制台应用程序.
这是我发现的:
string fileName = @"C:\data\stuff.txt";
ProcessStartInfo startInfo;
startInfo = new ProcessStartInfo(fileName);
if (File.Exists(fileName))
{
int i = 0;
foreach (String verb in startInfo.Verbs)
{
// Display the possible verbs.
Console.WriteLine(" {0}. {1}", i.ToString(), verb);
i++;
}
}
startInfo.Verb = "print";
Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)
既然你说这个问题不在主题而且不相关这里是我正在努力学习的链接:这是.Net框架的文档,这就是为什么我问这个问题,我正在努力学习.Net类的各种用法.
我正在学习C和C#,这个问题适用于C#.你为什么要在指针上使用out和ref关键字?使用指针,您可以直接访问变量.我在msdn上找到了这个代码:here.
这是代码:
static int value = 20;
public unsafe static void F(out int* pi1, ref int* pi2)
{
int i = 10;
pi1 = &i;
fixed (int* pj = &value)
{
// ...
pi2 = pj;
}
}
Run Code Online (Sandbox Code Playgroud) 我不知道此错误的含义以及如何解决该错误。
我一直在关注C入门的Sock)et编程教程| Eduonix的第2部分,在Youtube上,但是我一直无法从这个家伙那里运行任何东西,代码来自他的教程。
如果有人可以帮助我了解此错误的含义以及如何解决该错误?
这是错误:
inet_aton(address, &remote_address.sin_addr.s_addr);
^
Run Code Online (Sandbox Code Playgroud)
[1007:1003 0:6758] 09:30:39 Wed May 29 [kristjan@Kundrum:pts/5 +1] ~/C_Programming
$ gcc http_client_tcp.c -o http_client_tcp
http_client_tcp.c: In function ‘main’:
http_client_tcp.c:24:24: warning: passing argument 2 of ‘inet_aton’ from incompatible pointer type [-Wincompatible-pointer-types]
inet_aton(address, &remote_address.sin_addr.s_addr);
^
In file included from http_client_tcp.c:8:0:
/usr/include/arpa/inet.h:73:12: note: expected ‘struct in_addr *’ but argument is of type ‘in_addr_t * {aka unsigned int *}’
extern int inet_aton (const char *__cp, struct in_addr *__inp) __THROW;
^~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
我在Visual Studio …