【C#笔札】Tryparse的用法

这是参考读物的上得一个例子。自己仿照做的作业
private void button1_Click(object sender, EventArgs e)
{
int P_int_Number,i;
if (int.TryParse(n1.Text, out P_int_Number) && int.TryParse(n2.Text, out i))
{
Result.Text = (P_int_Number ^ i).ToString();
}
else
{
MessageBox.Show("请输入数值", "出现错误");
}
}
其中代码如上,基本上是一个异或加密
其中有段代码如下
if (int.TryParse(n1.Text, out P_int_Number) && int.TryParse(n2.Text, out i)) Tryparse第一次使用,特此记录用法 int.Parse()是一种类容转换;表示将数字内容的字符串转为int类型。 如果字符串为空,则抛出ArgumentNullException异常; 如果字符串内容不是数字,则抛出FormatException异常; 如果字符串内容所表示数字超出int类型可表示的范围,则抛出OverflowException异常; int.TryParse 与 int.Parse 又较为类似,但它不会产生异常,转换成功返回 true,转换失败返回 false。最后一个参数为输出值,如果转换失败,输出值为 0
int.TryParse(n1.Text, out P_int_Number) 其中第一个参数代表被转换的参数,第二个参数为转换后的参数 int类型,成功返回True,失败返回False。
【C#笔札】Tryparse的用法的更多相关文章
- tryParse的用法。
tryParse的用法. int.Parse()是一种类容转换:表示将数字内容的字符串转为int类型.如果字符串为空,则抛出ArgumentNullException异常:如果字符串内容不是数字,则抛 ...
- C#之Ref,Out以及TryParse()的用法
ref和out用法很简单,我记下来也提醒自己要用更好的方式去写代码,不要让代码过于臃肿,让人看得头痛.直接写 ref:ref关键字就是让参数进行传递,但是需要初始化,而out不需要初始化参数 ref用 ...
- C#中 int.TryParse 的用法
int i = -1;bool b = int.TryParse(null, out i);执行完毕后,b等于false,i等于0,而不是等于-1,切记. int i = -1;bool b = in ...
- tryparse的用法,^0*[1-9]\d*$
Entry entry = new Entry(); Int32 iParam; if(Int32.TryParse(entry.ajh,out iParam)) { /*如果转换成功就输出iPara ...
- WPF C# int.TryParse的用法
; if (!int.TryParse(item.Tag.ToString(), out comld)) { continue; } 没转换成功就continue 开始写成 if(GetNumber( ...
- TryParse()的用法
DateTime dt = new DateTime(); DateTime.TryParse(txtName.text.trim(),out dt); string str1 = dt.ToStri ...
- TryParse用法示例
int.Parse()是一种类型转换:表示将数字内容的字符串转为int类型.如果字符串为空,则抛出ArgumentNullException异常:如果字符串内容不是数字,则抛出FormatExce ...
- TryParse用法
int.Parse()是一种类型转换:表示将数字内容的字符串转为int类型. 如果字符串为空,则抛出ArgumentNullException异常: 如果字符串内容不是数字,则抛出FormatExce ...
- tryparse
[C#笔札]Tryparse的用法 这是参考读物的上得一个例子.自己仿照做的作业 private void button1_Click(object sender, EventArgs e) { ...
随机推荐
- SpringBoot系列教程起步
本篇学习目标 Spring Boot是什么? 构建Spring Boot应用程序 三分钟开发SpringBoot应用程序 本章源码下载 Spring Boot是什么? spring Boot是由Piv ...
- 基于JDK1.8的String源码学习笔记
String,可能是学习Java一上来就学习的,经常用,但是却往往只是一知半解,甚至API有时也得现查.所以还是老规矩,倒腾源码. 一.java doc 这次首先关注String的doc,因为其实作为 ...
- 牛客网多校赛第七场--C Bit Compression【位运算】【暴力】
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524 ...
- Excel 26机制转换
[问题描述] 在Excel中,列的名称是这样一个递增序列:A.B.C.….Z.AA.AB.AC.….AZ.BA.BB.BC.….BZ.CA.….ZZ.AAA.AAB….我们需要将上述列名序列和以下自然 ...
- D2 Magic Powder -1/- 2---cf#350D2(二分)
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
- matplotlib-曲线和折线案例
matplotlib-曲线和折线案例 import matplotlib.pyplot as plt import numpy as np x = np.linspace(-5, 5, 100) pr ...
- 003-spring cache-JCache (JSR-107) annotations
参看地址:https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache-js ...
- 翻译:Addressing tiles: same tile bounds with different indexes
原文链接:http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/ Addressing tiles: same ...
- oracle 查询按月份分组
如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- 14- ...
- ADB 清除Android手机缓存区域日志
原文地址http://blog.csdn.net/u013166958/article/details/79096221 Android系统的不同部分提供了四个不同log缓存区: /dev/log/m ...