使用按钮从文本框中找到最大的数字 [英] finding greatest number from text box using button

查看:72
本文介绍了使用按钮从文本框中找到最大的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个文本框中输入10个以逗号分隔的数字,然后使用按钮在其中找到最大的数字.请帮帮我.在此先谢谢您.

enter 10 numbers separated by comma(,) in one text box and find greatest number among them using button. Please help me out guys. Thanks in advance.

推荐答案

没有人会为您做功课-但是,这里有个提示->
使用String.Split命令在逗号上拆分字符串(在文本框中).
结果将是10个数字组成的数组,

只需使用任何排序方法对数组进行排序.
No one will do your homework for you - however, here is a hint ->
Use the String.Split command to split the string (inside the textbox) on the comma.
The result will be an array of 10 numbers,

Simply sort the array using any sort method.


由于这听起来像是作业,所以我不会给你代码!
不过,这并不困难:
1)在表单上放置一个TextBox和一个Button.给他们起个明智的名字-值得一开始就养成正确的习惯.
2)双击按钮以创建默认事件处理程序-click事件.这将带您进入代码.
3)从 Textbox.Text属性中读取数据[ ^ ],然后使用 string.Split方法 [ int.Parse [^ ]或int.TryParse [
Since this sounds like homework, I won''t give you code!
It''s not difficult though:
1) Put a TextBox and a Button on your form. Give them sensible names - this is worth getting into the habit of right from the beginning.
2) Double click the button to create the default event handler - the click event. This will take you to the code.
3) Read the data from the Textbox.Text property[^], and use the string.Split method[^] to separate them at the comma.
4) Loop though each string in the separated list, converting it to an integer with the int.Parse[^] or int.TryParse[^] method. Compare it with the current maximum value, if it is creater, then it becomes teh current maximum.
5) After the loop, the current maximum is the largest number.



这是执行此操作的代码:

Hi,
This is the code to do that:

public int GetGreatest(string numbers)
{
   string[] arr = numbers.Split(',');
   Array.Sort(arr);
   return int.Parse(arr[arr.length-1]);
}



希望对您有帮助,
干杯.



I hope it helps,
Cheers.


这篇关于使用按钮从文本框中找到最大的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆