我想在C#.NET中使用解决方案 [英] I want solution in C# .NET
问题描述
我想在c#.net中解决问题
问题1:我想在不使用此代码的情况下计算字符串的长度:(str.length.tostring();)或没有任何代码。在我的概念中,首先我想从文本框中获取价值
String str = textbox1.text;然后我想用整数转换它来计算文本框值
Int x = int32.parse(str);
Label1.text = x;
以我的方式显示代码。
问题2:我听说整数返回字符串,然后字符串返回什么?就像当我添加两个值时
Int x = convert.int32(textbox1.text);
Int y = convert.toint32(textbox2.text);
同样的输出应该是= convert.int32(textbox3.text);
输出= x + y;
但为什么我需要在strng中转换它= (X + Y);虽然输出将是整数。
问题3:没有try catch方法我想在添加两个数字时显示错误,如果我将textbox1或textbox2中的字符或字符串作为输入,它将显示错误消息put integer。我想用if else方法。
每个代码或解决方案应该很简单,因为我是初学者。并且请给出数据类型转换的时间和方式,我可以将整数转换为字符串,反之亦然,所有转换都是简短的解释示例。
我尝试过:
i在上面解释并尝试了我自己的概念。
I want solution in c# .net
Problem 1: I want to count the length of a string without using this code: (str.length.tostring();) or without any code. In my concept, first I want to take value from textbox
String str=textbox1.text; then I want to convert it in integer to count the textbox value
Int x=int32.parse(str);
Label1.text=x;
Show code in my way.
Problem 2: I heard that integer returns string, then string returns what? Like when I add two values
Int x=convert.int32(textbox1.text);
Int y=convert.toint32(textbox2.text);
Similarly output should be =convert.int32(textbox3.text);
Output=x+y;
But why I need to convert it in strng=(x+y); though the output will be in integer.
Problem 3: without try catch method I want to show error while adding two numbers that if I put character or string in textbox1 or textbox2 as input, it will show error message that "put integer". I want it in if else method.
Every code or solution should be simple as I am beginner. And please give data type conversions when and how I can convert integer to string and vice versa and all conversions short example with explanation.
What I have tried:
i explained above and tried in my own concept.
推荐答案
整数字符串是不同的野兽。
字符串的长度不等于字符串表示的整数。例如,字符串5
的长度1
,而(当然)表示整数5
。所以String.Length
属性和Int32.Parse
方法有不同的用途。
假设您想要实现一个简单的(例如只是一个加法器)计算器,您必须:
- 将数字的字符串表示形式转换为实际整数。
- 执行请求的(和预定义的)操作
- 将结果转换回字符串以便为用户生成输出
Integers an strings are different beasts.
The length of a string is NOT equal to the integer the string represents. For instance, the string"5"
has length1
while (of course) representing the integer5
. So theString.Length
property and theInt32.Parse
method serve a different purpose.
Assuming you want to implement a simple (e.g. just an adder) calculator you have to:
- Convert the string representation of the numbers to the actual integers.
- Perform the requested (and predefined) operation
- convert back the result to a string in order to produce the output to the user
这篇关于我想在C#.NET中使用解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!