我需要C#编程方面的帮助; 我是新手,我来自C背景.我有一个这样的控制台应用程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Add_Function
{
class Program
{
static void Main(string[] args)
{
int a;
int b;
int c;
Console.WriteLine("Enter value of 'a':");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of 'b':");
b = Convert.ToInt32(Console.ReadLine());
//why can't I not use it this way?
c = Add(a, b);
Console.WriteLine("a + b = {0}", c);
}//END Main
public int Add(int x, int y)
{
int result = x + y;
return result;
}//END Add
}//END Program …Run Code Online (Sandbox Code Playgroud) 我想问一下如何在程序加载时出现加载屏幕(只是图片或其他东西),并在程序加载完成后消失.
在发烧友的版本中,我看到了显示的进程条(%).你怎么能拥有它,你如何计算显示的百分比?
我知道有一个Form_Load()事件,但我没有看到Form_Loaded()事件,或者%作为属性/属性.
我想从另一个表单访问表单的变量.单击我的主窗体内的按钮,我想将我的主窗体设置为父窗口,然后调出另一个窗体(子窗体),其中我将访问主窗体的变量.我的点击处理程序如下:
private void btnSystem_Click(object sender, EventArgs e)
{
Form_EnterPassword EP = new Form_EnterPassword();
EP.Parent = this; //error: Top-level control cannot be added to a control
EP.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
它编译好没有任何错误.但是,当我运行Main窗体并单击System按钮时,它会抛出异常.我使用相同的按钮单击在另一个代码(不是我的)中执行类似的操作,并且不会遇到任何错误(仅将主窗体设置为父窗口).
我究竟做错了什么?我的主代码中是否有导致此问题的内容?
我想在Linux上用Gitkraken克隆一个远程仓库.由于没有创建新文件夹的权限,操作失败,尽管我以管理员身份登录.有人可以帮忙吗?
我看到以下声明:
ThreadStart myThreadDelegate = new ThreadStart(Work.DoWork);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
Run Code Online (Sandbox Code Playgroud)
他们可以简化如下吗?
Thread myThread = new Thread(new ThreadStart(Work.DoWork));
myThread.Start();
Run Code Online (Sandbox Code Playgroud)
如果是,那么第二种方法是什么?每种方法的优缺点是什么?
我创建了以下函数来获取日期时间字符串:
char *GetDateTime (int Format)
{
if (Format > 2) Format = 0;
double DateTimeNow;
int BufferLen;
char *DateTimeFormat [3] = { "%X %x" , //Time Date
"%x" , //Date
"%X" }; //Time
char *DateTimeBuffer = NULL;
GetCurrentDateTime (&DateTimeNow);
BufferLen = FormatDateTimeString (DateTimeNow, DateTimeFormat [Format], NULL, 0);
DateTimeBuffer = malloc (BufferLen + 1);
FormatDateTimeString (DateTimeNow, DateTimeFormat [Format], DateTimeBuffer, BufferLen + 1 );
return DateTimeBuffer;
}
Run Code Online (Sandbox Code Playgroud)
我不释放“DateTimeBuffer”,因为我需要传递它的内容。我想知道那段记忆是否会自行清除。请帮忙。
我尝试使用此功能复制文件,但输出文件包含奇怪的字符.
int File_Copy (char FileSource [], char FileDestination [])
{
int result = -1;
char c [1];
FILE *stream_R = fopen (FileSource, "r");
FILE *stream_W = fopen (FileDestination, "w"); //create and write to file
while ((c [0] = (char) fgetc(stream_R)) != EOF)
{
fprintf (stream_W, c);
}
//close streams
fclose (stream_R);
fclose (stream_W);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题.请帮忙.
对于我的一项作业,我被告知要使用cin.clear(ios_base::failbit)来设置failbit. cin.clear(ios_base::failbit)我想知道和 和有什么区别cin.setstate(ios_base::failbit)?后者不是更清楚吗?我有点惊讶地看到它failbit是如何设置的clear()。为什么要采用这种违反直觉的方式clear()?
我在网上看到了这段代码.但是,我无法理解while(true)在此代码中阻塞是如何发生的:
private void ListenForClients()
{
this.tcpListener.Start();
while (true)
{
//blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();
//create a thread to handle communication
//with connected client
Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
clientThread.Start(client);
}
}
Run Code Online (Sandbox Code Playgroud)
有谁可以向我解释一下?我知道使用while(true)+破坏条件,但这件事超出了我的意思.
我用来Directory.Exists()检查文件夹是否存在,但遇到该方法失败。我的命令是:
if (Directory.Exists(myFolder) == false)
{
MessageBox.Show(myFolder, "Invalid Log Folder path", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
if (Directory.Exists(myFolder) == true)
{
MessageBox.Show(myFolder, "Valid Folder path");
}
Run Code Online (Sandbox Code Playgroud)
当 myFolder 为 时,C:\Documents and Settings\UserID\My Documents它返回TRUE。
当 myFolder 是时C:\Documents and Settings\xxx\My Documents,它返回FALSE(假设xxx不存在)。
但是,当 myFolder 为 时,C:\\Documents and Settings\UserID\My Documents它也会返回TRUE.
旁边的双反斜杠C:必定使测试无效。然而,Directory.Exists()却没有认识到这一点。
使用更多\它仍然遇到同样的问题。
我只是无法理解这种失败是如何发生的。我正在使用 VS2008 和 .NET 3.5。