这是我的单选按钮
Runescape
Maplestory
League
Run Code Online (Sandbox Code Playgroud)
所以这是我当前的方法,它运行得很好。
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
MessageBox.Show("You are playing Runescape.");
}
else if (radioButton2.Checked)
{
MessageBox.Show("You are playing Maplestory.");
}
else if (radioButton3.Checked)
{
MessageBox.Show("You are playing League.");
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以像组合框一样打印出SelectedItem。基本上是单选按钮的文本。
组合框版本:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You are playing " + comboBox1.SelectedItem);
}
Run Code Online (Sandbox Code Playgroud)
与此类似的东西(不确定是否可能)。
MessageBox.Show("You are playing " + RadioButton.SelectedItem);
Run Code Online (Sandbox Code Playgroud) 双字母:连续出现两次的字母.(例如:"Google","编程好友")
Google包含1个双字母.编程伙伴在字符串中包含2个双字母.
不管怎样,这是我的代码
int doubleLetters = 0;
for (int i = 0; i < characters.Length - 1; i++)
{
if (characters[i] == characters[i + 1])
{
doubleLetters++;
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是如果一个字符串被拼写为"Gooogle"(3个O),它将返回2而不是1的数量.基本上,它会返回多少个连字号 - 结果为1.
我怎么做才能算出正确数量的双字母?因此,如果字符串是"looooool",它应该给出一个3.然而,我的代码将其计为5.
我正在尝试找到可以解决此问题的代码.
string pathFile = @"C:\Users\user\Downloads\CaptchaCollection\Small\Sorted\";
var files = Directory.GetFiles(pathFile).Select(nameWithExtension => Path.GetFileNameWithoutExtension(nameWithExtension)).Where(name => { int number; return int.TryParse(name, out number); }).Select(name => int.Parse(name)).OrderBy(number => number).ToArray();
List<int> fileList = files.ToList();
image1 = new Bitmap(pathFile + fileList[0].ToString() + ".png");
image2 = new Bitmap(pathFile + fileList[1].ToString() + ".png");
if (compare(image2, image2))
{
// if it's equal
File.Delete(image2.ToString());
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我现在所拥有的是每个文件都是数字的(没有扩展名).我创建了一个数组,然后将其转换为列表.
我使用我的全局变量image1,image2用于比较它们是否相同.
image1并image2随着搜索的进行而改变.所以它改变了索引.
如果我的compare()方法返回true,它将删除第二个图像.
但是,在该compare()方法上,我似乎在此行上收到此异常错误:
BitmapData bmpData2 = bmp2.LockBits(rect, ImageLockMode.ReadOnly, bmp2.PixelFormat);
Run Code Online (Sandbox Code Playgroud) 我想编写一个通用的帮助器,它采用实体类型名称并在其LINQ代码中使用它.
public Boolean Eval( )
{
var firstOrDefault = db.Class.OfType<Order>().FirstOrDefault;
}
Run Code Online (Sandbox Code Playgroud)
如何传入Order类型名称以使此代码更通用?我相信这是有用的<T>
我正在尝试用多个字符修剪一个字符串,但是不能正常工作,.
码:
static String xpto(String[] a)
{
string trimming;
foreach (string value in a)
{
//...
trimming = value.Trim(new Char[] { '(', ',', ')' });
//...
}
}
Run Code Online (Sandbox Code Playgroud)
样本输入:(1,2)
预计产量:12
我得到的是什么:1,2
也许与',','有些冲突?不知道为什么它不起作用!我可以使用split()3次(每个字符一个)到达我想要的地方,但我很困惑为什么这不起作用.
这是代码那么有一个问题 listener.Close();
为什么无法访问?
我有一个客户端和服务器,客户端将使用数组将结果提交给服务器
一切都在一段时间内完成(真实)
public void listen()
{
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 2112));
listener.Listen(10);
while (true) {
Socket socket = listener.Accept();
string receivedValue = string.Empty;
while (true) {
byte[] receivedBytes = new byte[1024];
int numBytes = socket.Receive(receivedBytes);
receivedValue += Encoding.ASCII.GetString(receivedBytes, 0, numBytes);
if (receivedValue.IndexOf("[ ]") > -1)
{
break;
}
string replyValue1 =string.Empty;
string replyValue2 = string.Empty;
string replyValue3 = string.Empty;
string replyValue4 = string.Empty;
string replyValue5 = string.Empty;
string replyValue6 = string.Empty;
string[] …Run Code Online (Sandbox Code Playgroud) 我目前在使用抛出异常的方法时遇到了一些问题,但我不确定原因.该异常使我的应用程序崩溃.
System.NullReferenceException: Object reference not set to an instance of an object.
at Myapp.AutoProcess.<ToRead>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Run Code Online (Sandbox Code Playgroud)
我在一个单独的线程上运行该方法
Thread listenerThread = new Thread(() => ToRead());
listenerThread.Start();
Run Code Online (Sandbox Code Playgroud)
抛出异常的方法如下所示:
private async void ToRead()
{
while (true)
{
if (this.toRead.Count != 0)
{ …Run Code Online (Sandbox Code Playgroud) 所以我有一个简单的表单,用户可以输入double值.

这就是我的表格应该是什么样子.
但是,如果用户有意或无意地输入非数字值,则会给我一个错误:
Input String was not correct format
Run Code Online (Sandbox Code Playgroud)
我听说过这样做的方法,称为异常处理.如何制作我自己的错误消息,以便程序不会崩溃?
c# ×8
string ×2
.net ×1
asp.net-mvc ×1
asynchronous ×1
bitmap ×1
c#-4.0 ×1
char ×1
exception ×1
linq ×1
radio-button ×1
split ×1
task ×1