我仍然是C#的新手,与C/CPP相比,我很难习惯它.
如何在不退出程序的情况下退出C#上的函数,就像这个函数一样?
if (textBox1.Text == "" || textBox1.Text == String.Empty || textBox1.TextLength == 0)
textBox3.Text += "[-] Listbox is Empty!!!!\r\n";
System.Environment.Exit(0);
Run Code Online (Sandbox Code Playgroud)
这将不允许返回类型,如果单独留下它将继续通过未停止的函数继续.这是不可取的.
如何将图像添加到选项卡控件上的选项卡标签?
像这样:

但在正常的标签页上,如下所示:
我明白这样做你需要添加一个Imagelist并对要使用的图像做一个索引,但我没有找到任何在google上搜索的例子.有帮助吗?
我一直在尝试使用此代码在html/ajax中按类读取元素,因为知道GetElementByClass不是webBrowser.Document中的选项.我似乎无法获得返回值然后调用该成员.有没有解决这个问题?
例:
<span class="example">(<a href="http://www.test.com/folder/remote/api?=test" onclick=" return do_ajax('popup_fodder', 'remote/api?=test', 1, 1, 0, 0); return false; " class="example">test</a>)</span>
Run Code Online (Sandbox Code Playgroud)
示例代码:
HtmlElementCollection theElementCollection = default(HtmlElementCollection);
theElementCollection = webBrowser1.Document.GetElementsByTagName("span");
foreach (HtmlElement curElement in theElementCollection)
{
//If curElement.GetAttribute("class").ToString = "example" It doesn't work.
// This should be the work around.
if (curElement.OuterHtml.Contains("example"))
{
MessageBox.Show(curElement.GetAttribute("InnerText")); // Doesn't even fire.
// InvokeMember(test) after class is found.
}
}
Run Code Online (Sandbox Code Playgroud) 在尝试了一些错误检查方法后,我得出结论,我需要帮助解决这个问题.
我怎么没有发现这个"索引超出范围"的错误.在未来的良好实践中,我该怎么做才能避免这个问题?
public void loadFromFile()
{
OpenFileDialog oFile = new OpenFileDialog();
oFile.Title = "Open text file";
oFile.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
oFile.FilterIndex = 1;
oFile.InitialDirectory = Application.StartupPath;
oFile.AddExtension = true;
oFile.CheckFileExists = true;
oFile.CheckPathExists = true;
// Open and clean Duplicates
String[] lines;
List<string> temp = new List<string>();
List<string> newlist = new List<string>();
if(oFile.ShowDialog() == DialogResult.OK)
{
// Dummy file has 6 lines of text. Filename:DuplicatFile.txt
// 3 duplicate lines and 3 not.
lines = File.ReadAllLines(oFile.FileName, System.Text.Encoding.UTF8);
// …Run Code Online (Sandbox Code Playgroud) 现在我将VB6项目移植到C#并继续收到此错误.似乎无法在命名空间中修复它.
问题:
//Expected class, delegate, enum, interface, or struct
public string GetHostByAddress(long addr)
{
dynamic phe = null;
dynamic Ret = null;
HOSTENT heDestHost = default(HOSTENT);
dynamic hostname = null;
phe = gethostbyaddr(addr, 4, PF_INET);
if (phe) {
MemCopy(heDestHost, phe, hostent_size);
hostname == new String[256, 0];
MemCopy(hostname, heDestHost.h_name, 256);
GetHostByAddress == Strings.Left(hostname, Strings.InStr(hostname, Strings.Chr(0)) - 1);
} else {
GetHostByAddress = WSA_NoName;
}
}
Run Code Online (Sandbox Code Playgroud)
原始方法看起来像这样.
Public Function GetHostByAddress(ByVal addr As Long) As String
Dim phe&, Ret&
Dim heDestHost As HOSTENT …Run Code Online (Sandbox Code Playgroud)