Unity/Csharp/配列のソースを表示
←
Unity/Csharp/配列
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
==配列宣言== int[] nums; float[] f; Vector3[] v; GameObject[] gameObjects; ==数字配列宣言&入力== int[] nums = {10,20,30,40,50,60,70,80,90,100}; or int[] nums = new int[10]; nums[0] = 10; nums[1] = 20; Debug.Log(nums[1]); // 20 ==文字列配列宣言&入力== string[] names = new string[] { "taro", "jiro", "saburo" }; Debug.Log(names[1]); // jiro ==クラスリスト== クラス例 <pre> class Car { public string name; public int value; public Car(string name, int value) { this.name = name; this.value = value; } } </pre> クラスリスト例 List<Car> cars = new List<Car>(); cars.Add( new Car("Lexas", 50)); ==クラスディクショナリ== Dictionary<string, Car> cars = new Dictionary<string, Car>(); Car bg1 = new Car("Lexas", 50); Car bg2 = new Car("Rx8", 100); cars.Add("Lexas", bg1); cars.Add("Rx8", bg2); Car car = cars["Lexas"]; ==ディクショナリをenumキーで== Dictionary<HogeType, Button> enumDict = new Dictionary<HogeType, Button>(); ==ディクショナリforeach== foreach(KeyValuePair<HogeType, Button> pair in enumDict){ Debug.Log (pair.Key + " " + pair.Value); } ==ディクショナリのキーの存在判定== <pre> if (cars.ContainsKey("Lexas")) { // 存在するとき } </pre> ==TryGetValueを使うとき== <pre> Car carvalue = null; cars.TryGetValue("Lexas", out carvalue); </pre> 参考:https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=net-5.0 ==List<string>に新規で追加== List<string> names = new List<string> { "taro", "jiro", "saburo" }; ==List<string>からstring[]へ== List<string> words = new List<string>(); words.Add("taro"); words.Add("jiro"); words.Add("saburo"); string[] wordStrings = words.ToArray(); ==string[]からList<string>へ== string[] wordStrings = {"taro","jiro","saburo"}; List<string> list = new List<string>(wordStrings); ==Listの3番目に入れる== list.InsertRange(3, "saburo"); ==Listの3番目のデータ取得== string name = list[2]; // 3 - 1 ==先頭に追加== List<string> names = new List<string>(); names.Insert(0, "taro"); ==順番逆順に== int[] nums = new int[] { 1, 2, 3, 4 }; nums.Reverse(); // 参照渡しとなり戻り値はvoid ==配列に文字数字が含まれてるか確認== List<string> names = new List<string>(); if (!names.Contains(name)) { } List<int> nums = new List<int>(); if (!nums.Contains(num)) { } ==配列シャッフル== <pre> public static List<int> Shuffle(List<int> list) { for (int i = list.Count - 1; i > 0; i--) { int j = Random.Range(0, i + 1); var tmp = list[i]; list[i] = list[j]; list[j] = tmp; } return list; } </pre> 参考:https://qiita.com/o8que/items/bf07f824b3093e78d97a ==検索== <pre> string[] src = {"taro", "jiro", "saburo"}; var list = new List<string>(); list.AddRange(src); string item = "jiro"; int num = list.IndexOf(item); if (num > -1) { Debug.Log("ari"); } </pre> ==配列の最初から削除== <pre> List<string> hoges = new List<string>(); hoges.Add("taro"); hoges.Add("jiro"); hoges.Add("saburo"); for (int a = 0; a <= 2; a++) { Debug.Log("hoge=" + hoges[0]); hoges.Remove(hoges[0]); } Debug.Log("count=" + hoges.Count); </pre> 出力 <pre> hoge=taro hoge=jiro hoge=saburo count=0 </pre> ==配列を,区切りで文字列に== List<string> words = new List<string>(); words.Add("taro"); words.Add("jiro"); words.Add("saburo"); string[] wordStrings = words.ToArray(); Debug.Log(String.Join(",", wordStrings)); // taro,jiro,saburo ==参考== 公式リストとディクショナリ https://unity3d.com/jp/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries
Unity/Csharp/配列
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
ソースを閲覧
履歴表示
その他
検索
案内
プログラムメモ
php
flutter
java
android
kotlin
ios
unity
unrealengine
javascript
mysql
sqlite
postgresql
oracle
mroonga
mongodb
flash
electron
cocos2dx
titanium
cpp
ruby
perl
python
accessメモ
rss
html
monaca
cordova
golang
blender
セキュリティ
テストツール
サーバメモ
linux
dotnet
apacheメモ
htaccessメモ
subversion
git
仮想サーバ
ansible
sendgrid
xampp
cacti
mecab
faces
flashpolicyd
fcs
jenkins
運用
デザインメモ
css
ユーザビリティ
ux
サービスメモ
twitter
facebook
instagram
mixi
セカンドライフ
通信ログ横取り
google
ustream
aws
gcp
plesk
azure
vps
AI
その他サービス
便利系メモ
SEO
モバイル
抽象変数名
DDD
クライアント
firefox
chrome
pgp
windows
mac
jmetar
Thunderbird
excel
libreoffice
vpnclient
doxygen
VisualStudioCode
fastlane
metaquest
cmsメモ
mediawiki
pukiwiki
wordpress
その他
資格
IT用語
pvを稼ぐ方法
将棋プログラム
その他
ログイン
ページ内
メインページ
最近の更新
人気のページ
問い合わせ
ツール
リンク元
関連ページの更新状況
ページ情報