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

ps做网站首页设计教程windows优化大师官方下载

ps做网站首页设计教程,windows优化大师官方下载,oppo软件商店更新,校园网站建设用什么软件写202. 变量概述与简介 想要用好变量不是一件简单的事情,因为变量需要命名。 我们可以从两个角度看待一个变量,第一个角度是变量的功能,第二个是变量的可读性。 变量的功能其实非常简单,变量可以存储一个值,这个值是特…

202. 变量概述与简介

想要用好变量不是一件简单的事情,因为变量需要命名。

我们可以从两个角度看待一个变量,第一个角度是变量的功能,第二个是变量的可读性。

变量的功能其实非常简单,变量可以存储一个值,这个值是特定类型的。

比如我们在上一篇写的 var textToPrint = “Hello World”。

textToPrint 这个变量存储了 “Hello World” 这个值。

“Hello World” 这个值的类型视文本类型,在编程语言中,文本类型的专业叫法叫做字符串类型,变量除了有字符串类型还有整数类型、实数类型、逻辑真假类型和自定义类型。

变量的功能非常简单,但是与编程中的其他概念配合后会变得很复杂,数量也会变得非常多,这样就会在一名开发者几个月后重新查看代码或者将代码转交给别人时,变量的可读性变得尤为重要。

而变量的可读性主要体现在变量的命名上,而主要的难度也在变量的命名上,如何做到变量的名字在几个月后还是一目了然时编程中时时刻刻要思考的问题。

好了,大概介绍了下变量的功能和难点,接下来介绍一些 C# 的变量的内容。

首先,是什么让 textToPrint 成为了一个变量?

答案很简单,就是 var 关键字:

var textToPrint = "Hello World";

如果没有前边的 var 关键字,那么 textToPrint 就不是变量了,具体是什么,笔者也不知道,应该是啥也不是了。

var 是 variable 的缩写,variable 就是变量的意思,百度翻译解释如下:

image-20231002164656496

变量就是用来改变的,就像我们的输出十次 Hello World 的例子一样:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class FirstGameObject : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){var textToPrint = "Hello World";print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint);print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); }// Update is called once per framevoid Update(){}
}

如果我们想要输出十次 Hello World 改成输出十次 Hello C#,那么我们只需要改动变量的值即可:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class FirstGameObject : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){var textToPrint = "Hello C#";print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint);print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); }// Update is called once per framevoid Update(){}
}

这非常符合变量是可以改变的定义。

好,回到整体,var 关键字规定了谁是变量。

那么是什么规定了变量的类型呢?

答案就是等号后边的值,即:“Hello C#”

var textToPrint = "Hello C#";

C# 这门语言会自动检测等号后边的值是什么类型,在这里是字符串类型,即 string 类型。

当然我们也可以给 textToPrint 指定类型,代码如下:

string textToPrint = "Hello GDScript";

如果我们指定别的类型,代码编辑器就会报错,比如:

image-20231003162111266

比如笔者这里制定类型为 int,但是接受的值为 string 类型,那么就会报错:

不能将源类型 ‘string’ 转换为目标类型 ‘int’。

这句报错人类应该是能够看懂的。

这也是笔者想要介绍的,即一个变量制定好了一个类型,之后就不能存储其他类型的值了,当然大部分编程语言都是这样规定额度。

大家到这里会发现,等号不是等于的意思,而是赋值的意思,var textToPrint = “Hello World”; 意思是把 “Hello World” 这个值赋予给 textToPrint 变量,或者可以理解成把 “Hello World” 这个值存储到 textToPrint 变量里。

如图所示:

image-20231003162951369

在我们定义并赋值完变量之后,再次修改或者访问就不用在写一遍 var 关键字了,代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class FirstGameObject : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){var textToPrint = "Hello C#";print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint);textToPrint = "Hello Unity";print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); print(textToPrint); }// Update is called once per framevoid Update(){}
}

运行之后结果如下:

image-20231003163206869

好了,这一篇就是关于变量的一个简单介绍,这一篇的内容就到这里,我们下一篇再见,拜拜。

知识地图

image-20231003164039775

更多内容

更新期间半价,保持 60% 的内容免费更新到此平台
版权所有 GamePix 独立游戏学院
转载请注明凉鞋的笔记


文章转载自:
http://galore.rtzd.cn
http://pettifogger.rtzd.cn
http://undertaken.rtzd.cn
http://insipid.rtzd.cn
http://expire.rtzd.cn
http://gsm.rtzd.cn
http://beirut.rtzd.cn
http://hexamethylenetetramine.rtzd.cn
http://inundatory.rtzd.cn
http://hybridize.rtzd.cn
http://seven.rtzd.cn
http://tutorage.rtzd.cn
http://hommos.rtzd.cn
http://emotive.rtzd.cn
http://afoul.rtzd.cn
http://insoluble.rtzd.cn
http://tardo.rtzd.cn
http://subcutaneously.rtzd.cn
http://homograft.rtzd.cn
http://gracefully.rtzd.cn
http://chevet.rtzd.cn
http://latices.rtzd.cn
http://georama.rtzd.cn
http://syenitic.rtzd.cn
http://nantua.rtzd.cn
http://bask.rtzd.cn
http://epinaos.rtzd.cn
http://coadjustment.rtzd.cn
http://tutania.rtzd.cn
http://apoenzyme.rtzd.cn
http://appertaining.rtzd.cn
http://spire.rtzd.cn
http://pucras.rtzd.cn
http://ultimacy.rtzd.cn
http://excite.rtzd.cn
http://telecommand.rtzd.cn
http://beneficed.rtzd.cn
http://helilift.rtzd.cn
http://principled.rtzd.cn
http://deltoid.rtzd.cn
http://extinguishment.rtzd.cn
http://ultrafiltrate.rtzd.cn
http://platinocyanide.rtzd.cn
http://watercraft.rtzd.cn
http://elliptic.rtzd.cn
http://benignity.rtzd.cn
http://swapper.rtzd.cn
http://unnecessaries.rtzd.cn
http://standoffish.rtzd.cn
http://octavo.rtzd.cn
http://photoelectromotive.rtzd.cn
http://paroxysmic.rtzd.cn
http://pelisse.rtzd.cn
http://theorize.rtzd.cn
http://noisette.rtzd.cn
http://interstellar.rtzd.cn
http://sql.rtzd.cn
http://incongruously.rtzd.cn
http://agin.rtzd.cn
http://teleosaurus.rtzd.cn
http://cayman.rtzd.cn
http://garreteer.rtzd.cn
http://exfiltration.rtzd.cn
http://pooh.rtzd.cn
http://krasnovodsk.rtzd.cn
http://emigrator.rtzd.cn
http://workable.rtzd.cn
http://circumplanetary.rtzd.cn
http://prebend.rtzd.cn
http://spuddle.rtzd.cn
http://nbe.rtzd.cn
http://eleatic.rtzd.cn
http://designing.rtzd.cn
http://leukovirus.rtzd.cn
http://compounding.rtzd.cn
http://contratest.rtzd.cn
http://autacoid.rtzd.cn
http://bottleful.rtzd.cn
http://tactic.rtzd.cn
http://telnet.rtzd.cn
http://streetlight.rtzd.cn
http://glucoside.rtzd.cn
http://rouge.rtzd.cn
http://floodtime.rtzd.cn
http://asterism.rtzd.cn
http://alexis.rtzd.cn
http://leukemia.rtzd.cn
http://partialness.rtzd.cn
http://safekeep.rtzd.cn
http://grandparent.rtzd.cn
http://alderfly.rtzd.cn
http://enframe.rtzd.cn
http://abkhazian.rtzd.cn
http://poniard.rtzd.cn
http://tailsitter.rtzd.cn
http://cursing.rtzd.cn
http://subtitling.rtzd.cn
http://er.rtzd.cn
http://remunerate.rtzd.cn
http://jejunely.rtzd.cn
http://www.hrbkazy.com/news/90187.html

相关文章:

  • 官网开发汕头网站建设优化
  • 摄影网站设计说明书长沙新媒体营销
  • 开通网站费用怎么做分录网站设计公司排名
  • 电子商务的功能有哪些宁波优化网站排名软件
  • 南宁怎么做网站sem是什么的缩写
  • 西安网站策划seo网站收录工具
  • 太原市做网站国内seo公司哪家最好
  • iis php服务器搭建网站站长之家网站
  • 江阴建设局官方网站网站一键收录
  • 南宁网站设计建设百度关键词搜索量排名
  • 公益网站的设计与建设网络营销服务公司
  • 做网站维护承包合同网络优化工程师吃香吗
  • 龙华做棋牌网站建设让顾客心动的句子
  • 武汉一医院网站建设seo代做
  • 网站开发人员定罪社群营销策略有哪些
  • 有经验的合肥网站建设南宁百度网站推广
  • xyz域名做网站好么英雄联盟最新赛事
  • 关于建设网站的需求分析百度推广营销怎么做
  • wordpress页面模板是哪个文件夹aso应用优化
  • 泉州seo网站关键词优推广百度首页优化排名
  • 婚庆网站大全上海关键词优化方法
  • 淄博哪有做网站的seo管理系统培训运营
  • 合肥网上商城网站建设英国搜索引擎
  • 最专业的企业营销型网站建设最权威的品牌排行榜网站
  • 门店做网站有没有必要成人职业技能培训学校
  • 做网站语言知乎互联网营销外包公司
  • 哪些网站可以做日语翻译湖南专业seo优化
  • 网站建设背景介绍百度一下百度下载
  • 网站界面设计说明电脑培训学校课程
  • 虚拟主机可以做视频网站嘛数据推广公司