当前位置:网站首页>Unity3d learning notes-1 (C # learning)
Unity3d learning notes-1 (C # learning)
2022-06-30 05:03:00 【dai014】
2022/2/10
The starting point : stay ts Common tools and methods in : Get an array , Random return of a value in an array
step1:
public static T RandomArray<T>(T[] arr)
{
Random random = new Random();
int index = random.Next(0, arr.Length);
return arr[index];
}
step2:
It is found that what needs to be random is an enumeration type , Convert enumeration type to array , I tried to write it myself , It is found that there are methods that can be called directly
Enum.GetValues(typeof(Animal));
But its return type is Array, After finding , This is the base class of array type , Try turning it into an enumerated array , The attempt failed , There is no way ( Base class cannot be converted to derived class ?)
step3:
After an attempt to convert to an array failed , introduce List
List<Animal> animal_arr = new List<Animal>(Enum.GetValues(typeof(Animal)).Length);
step 4:
introduce List Later, it was found that the original generic tool method could not be used , So it is overloaded , But the return can only use object 了
public static object RandomArray(Array arr)
{
Random random = new Random((int)DateTime.Now.Ticks);
int index = random.Next(0, arr.Length);
return arr.GetValue(index);
}
Summarize questions :
doubt 1:
How to convert an enumeration type directly to an array of enumeration types ?
doubt 2:
obtain Array How to convert to a subclass after a type ?
边栏推荐
- Ripple effect of mouse click (unity & shader)
- Solution to 293 problems in the week of Li Kou
- 力扣59. 螺旋矩阵 II
- Tensorflow2 of ubantu18.04 X installation
- Deeply understand the function calling process of C language
- How to install win7 on AMD Ruilong CPU A320 series motherboard
- Li Kou 2049: count the number of nodes with the highest score
- Unreal 4 learning notes - set player birth point
- Four methods of unity ugui button binding events
- 力扣589:N 叉树的前序遍历
猜你喜欢

Win10 vs2015 compiling curaengine

【VCS+Verdi聯合仿真】~ 以計數器為例

Li Kou 2049: count the number of nodes with the highest score

Introduction to some representations, neighbors and degrees of Graphs

Some books you should not miss when you are new to the workplace

【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example

SCM learning notes: interrupt learning

MinGW-w64下载文件失败the file has been downloaded incorrectly!

Deep learning ----- different methods to realize inception-10

Photon pun refresh hall room list
随机推荐
Procedural animation -- inverse kinematics of tentacles
Unit screenshot saved on the phone
Unity3d Google Earth
Force buckle 27 Removing Elements
Four methods of unity ugui button binding events
Keywords implements and @override
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
C # equipment synthesis
003-JS-DOM-Attr-innerText
PS1 Contemporary Art Center, Museum of modern art, New York
Unreal 4 learning notes - set player birth point
【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example
Singapore parent-child tour, these popular attractions must be arranged
Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor
Unity/ue reads OPC UA and OPC Da data (UE4)
0 basic unity course. Bricklaying
Easyrecovery data recovery software recovers my photo and video data two years ago
pycharm 数据库工具
力扣周赛293题解
Oracle-数据的基本操作