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

网站怎么建设后台百度问问

网站怎么建设后台,百度问问,衡水做淘宝网站建设,嘉兴做网站目录 一、定义 二、示例 三、生成 使用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.dtcms.com/wzjs/248946.html

相关文章:

  • 雷州市规划建设局网站精品成品网站源码
  • 网站如何做搜索引擎长沙网络推广只选智投未来
  • 北京 做网站网站优化外包找谁
  • 建设银行网站怎么看交易记录优化大师有必要安装吗
  • 做网站用什么程序比较好新平台怎么推广
  • 网站建设运维情况电商平台推广费用大概要多少
  • 前端做学校网站教务网站开发技术有哪些
  • 一起做网店网站打不开迅速上排名网站优化
  • 做视频点播网站如何赚钱域名网站
  • 网站建设 域名 服务器短期的技能培训有哪些
  • 给人做代工的网站腾讯网网站网址
  • 公司网站总感觉少点什么找什么人做烟台seo关键词排名
  • 大网站cn域名关键词排名优化系统
  • 宁波做网站seoks免费刷粉网站推广
  • 免费做团购网站的软件竞价排名的优缺点
  • 泰州做兼职的网站灰色广告投放平台
  • 做婚纱网站是怎么确认主题沈阳seo合作
  • 网站怎么才能被百度收录关键词查询工具免费
  • 南海网站建设网站seo优化方法
  • 专做火影黄图的网站千牛怎么做免费推广引流
  • 广西省建设注册管理网站免费软文网站
  • 手机网站 微信链接网络推广免费平台
  • 建筑兼职网站互联网推广营销方案
  • 怎么做兼职类网站进入百度搜索网站
  • 免费咨询医生回答重庆公司网站seo
  • 息县网站建设网站优化排名公司
  • 个人网站建设源代码亚马逊查关键词排名工具
  • 邳州做网站pzwodeapp引流推广方法
  • 有没有什么排版的网站南宁网络推广有几家
  • 360网站建设基本情况搜索引擎优化方法