00:00
好了啊,接下来呢,咱们再讲其他的类型啊,有一个any类型,所以有的时候呢,我们想要为那些在编程阶段还不清楚的类型的变量指定一个类型。然后这些值呢,可能来自于动态类型的内容,比如说来自用户输入输入或者是第三方的库是吧,这个我就不再读了啊,它主要的意思是什么呢?就说我希望有一个类型,它定义的变量可以存储任何类型的数据,那这个时候我就可以用到I了啊,然后咱们来看一看,非常的方便啊。好,在这再来一个。Any类型。嗯,好比说light是吧,Str冒号an NY,等于把一个100,然后去canl点那个括号,括号str是吧?啊,保存一下,我们看一下结果啊。好,我们来看存了一个100是吧,可以存数字,那这个时候呢,如果说我再来一个str等于单引号。嗯,年少不知富婆好错,把少女当成宝,诶,搞定,然后我们再去保存一下。
01:12
大家看一下它也仍然可以是吧,而且任何问题都没有,所以说这个any类型啊,还是比较强大的一个类型。只要是什么呢?诶。我们不确定当前这个数据到底是什么类型的时候,那么我又想把它存储起来,那我就可以使用any是吧?好,再比如啊,我们再举例子。我把这个呢先注释掉。再比如说来一个let a是吧,冒号,我这边写个any,然后中括号等于中号,我里边想存个100,我里边想存个租串,比如说这个租串的话就是年少不知。嗯,诶。年少不知软饭香。香香甜可口是吧,那下一句是什么呢?错把错把,青春青春。
02:06
稻插秧。啊,这句话是什么意思,我也没太理解啊,只是记住这么一首词而已啊好,然后呢,再往后我再来一个触是不是?那我再去CAno.log括号A保存,我们看结果啊。也可以编译成功,并且也可以把内容展示出来是吧?那什么时候会用到这种东西呢?是不是啊,当一个数组中要存储多个数据,逗号个数不确定是不是?哎,类型不确定,那么此时也可以使用什么呢?Any类型来定义数组是吧?这个东西还是很香的啊,比较好用。啊,当然有好处也有坏处啊,这个坏处呢,咱们后边会知道啊,比如我现在就给大家去演示一下吧,是吧。
03:00
先演示它的一个不好的地方,比如说呢,我去CAno.log个括号,我想把数组里边的第一个数据拿出来调split方法,大家看能不能调啊,不能调是吧?哎,不能调,当然它能不能编译通过呢,咱们来看一下。我去刷新。哎,大家看啊,年少不知软饭香是吧,那我这块写一就是第二个数据嘛,啊,所以为一的这个数据点split它没有报错,也没有提示可以用是吧,那我这个位置如果写的是零呢,咱们再来保存一下,它也没有报错信息,这种情况下也没有这个错误的提示信息,所以说啊an NY类型。有优点。优点。逗号也有什么呢,缺点是吧?所以说还是那句话啊,有好就有坏啊是不是?保存一下,大家看这报错了吧,很明显吧,是不是它编译可以通过,但是最终会报错,为什么呢?因为这是一个数字类型,数字类型没有方法,所以说他就给我们报错了啊。
04:09
啊,这是它的缺点啊,好,这是any类型,然后呢,我们接着往后看啊。下一个啊,VO,从某某种程度上来说,VO类型呢,像是与any类型相反,Any代表的是任意类型,可以认为是,但是呢,呃,这个VO它表示的是什么呢?没有任何类型,什么时候会用呢?当一个函数没有返回值的时候,你通常会见到一个其返回值是void类型的啊,比如说举个例子啊。这个是void类型啊,来上一个方式,比如说呢,来一个收。收什么呢?收MSG吧是吧,哎,然后呢,这个函数它没有返回值,那通常情况下我们会写个冒号word,哎,然后呢,在这里边CAno.log随便吧,我们说说一句话吧,是吧,呃,这句话就什么呢?嗯。
05:05
哎,只要嗯,富婆把握住。逗号连夜搬进。搬进大别墅,然后呢,我们来看啊。那我就去调呗,是吧,调收MSG括号保存一下。我们来看一下这个结果直接输出了,没有任何内容是吧,那我能不能把它给输出一下。他没有返回值啊。那这个结果大家猜测一下是什么呀?应该是UN find是吧,这也正常,好,那这种情况下是代表当前这个函数没有返回值,那所以说呢,我们只需要在函数的后边写个冒号,Y代表该函数的返回值是什么呢?没有任何类型,没有任何反回值啊,注意Y类型在函数名字,在函数声明的时候啊,小括号的后面使用什么呢?冒号word。
06:05
代表的是该函数没有任何的返回值,哎,那这个时候就奇怪了,如果说我就写上一个return呢?保存一下,我们看和刚才结果一样不一样呢。K一样是吧,返回结果是二啊,那比如说我注释掉。我如果写上一个return on呢?保存一下,我们再来看一下这个结果啊。大家看结果和刚才也是一样的是吧,好,那我如果说把它注释掉,我再来一个什么呢?Return now呢,诶再保存。我们再来看一下。哎,结果是,那其实结果是,那代表它这个函数也是没有返回值的是吧?啊Y的类型通常情况下很少用,当然有的时候我们可能会见到有人会这么写啊,比如说这个啊VD吧,然后冒号Y,然后等于。然后呢,我们去CAno.log这个VD啊。
07:01
看一下这个结果。那我们看一下结果是按find,你说这样有意义吗?其实也没有多大意义啊,所以说啊,这个是定义VO o void类型的变量,然后呢,可以接收一个UN de FA的这个值啊,但意义不是很大。逗号,但是意义不是很大啊,好了,呃,那上面呢,咱们讲了一个any类型啊,可以存储任意类型的数据,还讲了一个什么呢?Y啊,没有任何类型是吧?通常情况下可以把它放在一个没有返回值的函数的后边,告诉别人这个函数是没有返回值的啊,这样也行啊,那我再写上一个KO点的括号,来一个华丽的分割线啊。保存一下,好先到这里。
我来说两句