当前位置: 首页 > news >正文

网站建设公司 北京seo伪原创工具

网站建设公司 北京,seo伪原创工具,海安建设局网站,中国人才热线目录 一、定义 二、示例 三、生成 使用as关键字可以将对象转换为指定类型,与is关键字不同,is关键字用于检查对象是否与给定类型兼容,如果兼容则返回true,如果不兼容则返回false。而as关键字会直接进行类型转换,如果…

目录

一、定义

二、示例

三、生成


        使用as关键字可以将对象转换为指定类型,与is关键字不同,is关键字用于检查对象是否与给定类型兼容,如果兼容则返回true,如果不兼容则返回false。而as关键字会直接进行类型转换,如果转换成功将会返回转换后的对象,如果转换不成功则不会抛出异常而是返回NULL。

一、定义

        as关键字用于引用类型之间执行转换。

        as关键字与is关键字一样都不会抛出异常,但是相比之下as关键字要更方便一些。

二、示例

        首先创建一个字符串对象,然后将字符串对象隐式转换为object类型的对象Temp_obj,使用as关键字将Temp_obj转换为字符串对象,最后检查字符串对象是否为空。如果为空,则转换不成功;如果不为空,则转换成功并执行后面的语句块。

// 使用as关键字将对象转换为指定类型
namespace _026
{public partial class Form1 : Form{private GroupBox? groupBox1;private RadioButton? radioButton3;private RadioButton? radioButton2;private RadioButton? radioButton1;private Label? label1;private Button? button1;public Form1(){InitializeComponent();Load += Form1_Load;}private void Form1_Load(object? sender, EventArgs e){// // label1// label1 = new Label{AutoSize = true,Location = new Point(29, 21),Name = "label1",Size = new Size(43, 17),TabIndex = 0,Text = "将FileStream对象转换为:"};// // radioButton1// radioButton1 = new RadioButton{AutoSize = true,Location = new Point(180, 17),Name = "radioButton1",Size = new Size(102, 21),TabIndex = 1,TabStop = true,Text = "转换为object类型",UseVisualStyleBackColor = true};// // radioButton2// radioButton2 = new RadioButton{AutoSize = true,Location = new Point(180, 41),Name = "radioButton2",Size = new Size(102, 21),TabIndex = 2,TabStop = true,Text = "转换为Stream类型",UseVisualStyleBackColor = true};// // radioButton3// radioButton3 = new RadioButton{AutoSize = true,Location = new Point(180, 65),Name = "radioButton3",Size = new Size(102, 21),TabIndex = 3,TabStop = true,Text = "转换为String类型",UseVisualStyleBackColor = true};// // groupBox1// groupBox1 = new GroupBox{Location = new Point(0, 1),Name = "groupBox1",Size = new Size(354, 103),TabIndex = 0,TabStop = false,Text = "类型转换"};groupBox1.Controls.Add(radioButton3);groupBox1.Controls.Add(radioButton2);groupBox1.Controls.Add(radioButton1);groupBox1.Controls.Add(label1);groupBox1.SuspendLayout();// // button1// button1 = new Button{Location = new Point(137, 110),Name = "button1",Size = new Size(75, 23),TabIndex = 0,Text = "转换类型",UseVisualStyleBackColor = true};button1.Click += Button1_Click;// // Form1// AutoScaleDimensions = new SizeF(7F, 17F);AutoScaleMode = AutoScaleMode.Font;ClientSize = new Size(354, 141);Controls.Add(button1);Controls.Add(groupBox1);Name = "Form1";StartPosition = FormStartPosition.CenterScreen;Text = "as关键字转换类型";           groupBox1.ResumeLayout(false);groupBox1.PerformLayout();}private void Button1_Click(object? sender, EventArgs e){if (radioButton1!.Checked)                //选择转换为object类型{using FileStream Temp_filestream =    //创建文件流对象new(@"d:\log.txt", FileMode.Create);if (Temp_filestream != null)          //判断转换是否成功{MessageBox.Show("转换为Object成功!", "提示!");}else{MessageBox.Show("转换为Object失败!", "提示!");}}if (radioButton2!.Checked)               //选择转换为stream类型{using FileStream Temp_filestream =   //创建文件流对象new(@"d:\log.txt", FileMode.Create);object Temp_obj = Temp_filestream;if (Temp_obj as Stream != null)      //判断转换是否成功{MessageBox.Show("转换为Stream成功!", "提示!");}else{MessageBox.Show("转换为Stream失败!", "提示!");}}if (radioButton3!.Checked)                //选择转换为string类型{using FileStream Temp_filestream =    //创建文件流对象new(@"d:\log.txt", FileMode.Create);object Temp_obj = Temp_filestream;if (Temp_obj as string != null)       //判断转换是否成功{MessageBox.Show("转换为String成功!", "提示!");}else{MessageBox.Show("转换为String失败!", "提示!");}}}}
}

三、生成

 

 

 

http://www.hkea.cn/news/387039/

相关文章:

  • 温州做网站技术员沧州做网络推广的平台
  • wordpress media上海排名优化seobwyseo
  • 深圳网站建设科技有限公司注册一个网站
  • 网站设计改版seo关键词优化推广价格
  • 做网站什么主题比较好上海网站seo诊断
  • 设计苹果手机的网站病毒什么时候才能消失
  • 国外做化工产品的网站自媒体发布平台
  • 怎么做资源类网站百度搜索热度排名
  • 大片网站建设seo关键词排名优化评价
  • 网络营销推广课程培训苏州seo门户网
  • 做盗版影视网站如何给公司网站做推广
  • 做网站付费流程郑州seo技术
  • 云南网站开发有哪些实用的网络推广方法
  • 央视新闻最新消息今天什么叫seo
  • 网站建设的意义徐州百度推广
  • 建设网站建设的目标百度云盘资源
  • 个体工商户是否能够做网站在线生成个人网站源码
  • 临沂高端网站建设厦门网站推广费用
  • 网站模版友链交易交易平台
  • 武汉做网站找谁百度导航是哪个国家的
  • wordpress互动游戏黄石seo诊断
  • 网页设计作品下载志鸿优化设计
  • 宾馆网站制作seminar是什么意思
  • 网站建设的进度表爱站查询工具
  • 深圳聘请做网站人员长春刚刚最新消息今天
  • 汽配人网做网站沈阳网站seo公司
  • 网站 短链接怎么做网站建设网站定制
  • 网站开发凭证做什么科目百度推广关键词多少合适
  • 网站正在建设 h5模板新闻热点
  • 龙岗公司网站建设怎么上百度搜索