Unity3d , Arrays and Collections

June 12, 2012   ·   0 Comments

数组C#(Array)
TheType myArray = new TheType[lengthOfArray];
int[] myNumbers = new int[10];
GameObject[] enemies = new GameObject[16];
int howBig = myArray.Length;
myArray[i] = newValue;
TheType thisValue = myArray[i];
数组JS(Array)
var myArray = new TheType[lengthOfArray];
var myNumbers = new int[10];
var enemies = new GameObject[16];
var howBig = enemies.Length;
myArray[i] = newValue;
var thisValue = myArray[i]
var weapons = [“Sword”, “Knife”, “Gun”];
//JS特有的用法
var myArray = new Array();
myArray.Add(anItem);
var thisItem = myArray[i];
myArray.RemoveAt(i);
var howBig = myArray.length;

数组链表(ArrayList)JS
var myArrayList = new ArrayList();
myArrayList.Add(anItem);
myArrayList[i] = newValue;
var thisItem : TheType = myArray[i];
myArray.RemoveAt(i);
var howBig = myArray.Count;
数组链表(ArrayList)C#
ArrayList myArrayList = new ArrayList();
myArrayList.Add(anItem);
myArrayList[i] = newValue;
TheType thisItem = (TheType) myArray[i];
myArray.RemoveAt(i);
var howBig = myArray.Count;

Hashtable (JS)
var myHashtable:Hashtable = new Hashtable();
myHashtable[anyKey] = newValue;
var thisValue : ValueType = myHashtable[theKey];
var howBig = myHashtable.Count;
myHashtable.Remove(theKey);
Hashtable (C#)
Hashtable myHashtable = new Hashtable();
myHashtable[anyKey] = newValue;
ValueType thisValue = (ValueType)myHashtable[theKey];
int howBig = myHashtable.Count;
myHashtable.Remove(theKey);

List(C#)泛型

using System.Collections.Generic;
List myList = new List();
List someNumbers = new List();
List enemies = new List();
myList.Add(theItem);
myList[i] = newItem;
Type thisItem = List[i];
myList.RemoveAt(i)

List(JS)泛型

import System.Collections.Generic;

var myList : List. = new List.();
var someNumbers = new List.();
var enemies = new List.();
myList.Add(theItem);
myList[i] = newItem;
var thisItem = List[i];
myList.RemoveAt(i);

Dictionary(C#)泛型
Dictionary myDictionary = new Dictionary();
Dictionary myContacts = new Dictionary();
myDictionary[anyKey] = newValue;
ValueType thisValue = myDictionary[theKey];
int howBig = myDictionary.Count;
myDictionary.Remove(theKey);

Dictionary(JS)泛型
var myDictionary : Dictionary. = new Dictionary.();
var myContacts = new Dictionary.();
myDictionary[anyKey] = newValue;
var thisValue = myDictionary[theKey];
var howBig = myDictionary.Count;
myDictionary.Remove(theKey);

2维数组(C#)
string[,] myArray = new string[16,4];
Tile[,] map = new Tile[32,32];
myArray[x,y] = newValue;
ValueType thisValue = myArray[x,y];
int width = myArray.GetLength(0);
int length = myArray.GetLength(1);
2维数组(JS#)

var myArray : String[,] = new String[16,4];
var map = new Tile[32,32];
myArray[x,y] = newValue;
var thisValue = myArray[x,y];
var width = myArray.GetLength(0);
var length = myArray.GetLength(1);

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon