Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
UnityC# for Beginner
Search
mattak
June 21, 2016
Programming
0
360
UnityC# for Beginner
Presentated in Unity3D study
mattak
June 21, 2016
Tweet
Share
More Decks by mattak
See All by mattak
最近やった作業環境改善施策10個
mattak
0
240
UnixTime is Simple
mattak
0
160
おっさんが停滞しないために
mattak
32
18k
tech invest
mattak
1
300
Nodux - node base redux framework
mattak
0
1.4k
what_is_technical_investment
mattak
0
120
unitypackage distribution
mattak
0
760
Unity energy usage
mattak
0
850
Unidux 0.3.1
mattak
1
360
Other Decks in Programming
See All in Programming
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
Remix on Hono on Cloudflare Workers
yusukebe
1
280
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
110
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Jakarta EE meets AI
ivargrimstad
0
530
Click-free releases & the making of a CLI app
oheyadam
2
110
Quine, Polyglot, 良いコード
qnighy
4
640
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
65
11k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Visualization
eitanlees
145
15k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Rails Girls Zürich Keynote
gr2m
94
13k
For a Future-Friendly Web
brad_frost
175
9.4k
Speed Design
sergeychernyshev
24
610
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Done Done
chrislema
181
16k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
6OJUZ$ೖ _จ๏ฤ_ 6OJUZษڧձ !NBUUBL
ࠓͷϝχϡʔʂ
(FOFSJDT MBNCEBEFMFHBUF FWFOU FOVN FYUFOTJPO
OVMMBCMF WBS ಗ໊ܕ OBNFTQBDF 1SPQFSUZ QBSUJBMUZQF ZJFME PVU -*/2 $จ๏
$จ๏ฤ
(FOFSJDT
List<string> list = new List<string>(); HFOFSJDT ૯শܕ ͕͋Δͱ͜͏ॻ͚Δ
ͳͥ૯শܕ͕͋Δͷ͔ʁ ૯শܕ͕ͳ͍ੈքΛߟ͑Δ List list = new List(); List<object> list =
new List<object>(); ͭ·Γͯ͢ͷཁૉ͕PCKFDUܕͰอଘ͞ΕΔ
ͳͥ૯শܕ͕͋Δͷ͔ʁ int id = (int)list[0]; string name = (string)list[0]; PCKFDUܕΛDBTUͯ͠औΓग़͢ඞཁ͕͋Δ
int id = intList[0]; ܕ͕ܾ·͍ͬͯΕɺΩϟετෆཁͰ҆શʹॻ͚Δ IntList intList = new IntList();
IntList, StringList, HogeList, … Ͱܕ͝ͱʹΫϥεΛఆٛͨ͘͠ͳ͍ ͳͥ૯শܕ͕͋Δͷ͔ʁ List<T> => List<int>, List<string>,
… ͦ͜Ͱ۩ମతͳܕΛ໌ࣔͤͣϩδοΫ͕͔͚Δͱ ൚༻ੑ͕͔͍ͨɹ ͜ΕΛ࣮ݱ͢ΔͨΊɺநతͳܕهड़͕Ͱ͖Δ (FOFSJDT1SPHSBNNJOH
ͦͷଞಛ $Ͱ૯শܕʹࡉ੍͔͍Λ͚ͭΒΕΔ 50%0XIFSFͷઆ໌ॻ͘ https://ja.wikipedia.org/wiki/C_Sharp#.E3.82.B8.E3.82.A7.E3.83.8D.E3.83.AA.E3.82.AF.E3.82.B9 $ͷ(FOFSJDT$ ͷςϯϓϨʔτ+BWBͱҟͳΔ ࣮ߦ࣌ʹಛघԽ͞ΕΔ
MBNCEB EFMFHBUF
$Ͱؔͷܕએݴ͕Ͱ͖Δ delegate void Hello(string name); ҾͱฦΓ͕ಉ͡Ͱ͋Εɺಉؔ͡ܕͱΈͳ͞ΕΔ
͍ΖΜͳ࣮͕ؔग़དྷΔ public class Person { void SayHello(string name) { Debug.Log("Hello,
" + name); } void Start() { Hello hello = SayHello; } } )FMMPܕͷؔ
Hello hello = (string name) => { Debug.Log("Hello, " +
name); }; Hello hello = delegate(string name) { Debug.Log("Hello, " + name); }; ແ໊EFMFHBUF ແ໊EFMFHBUF লུ
ແ໊EFMFHBUF ߋʹলུ Hello hello = (name) => { Debug.Log("Hello, "
+ name); }; ແ໊EFMFHBUF ߋʹߋʹলུ Hello hello = name => Debug.Log("Hello, " + name);
hello("John"); ݺͼग़͢ͱ͖ͯ͢
FWFOU
LFZXPSEͰFWFOU͕༧͞Ε͍ͯΔ ͋ΔEFMFHBUFܕΛFWFOUͱͯ͠એݴ͢Δ͜ͱ͕Ͱ͖Δ FWFOUʹෳͷ͕ؔొͰ͖Δ ొղআग़དྷΔ event Hello hellos; hellos += SayHello;
hellos += (name) => Debug.Log("Hello, " + name); hellos -= SayHello;
ొ͞ΕͨؔΛҰؾʹݺͼग़͢͜ͱ͕Ͱ͖Δ hellos("John");
FOVN
public enum Animal { Monkey, Lion, Cat, Dog } ͷྻڍ͕Ͱ͖Δ
public enum Animal : int { Monkey = 0, Lion,
Cat, Dog } FOVNʹରͯ͠Λඥ͚ΒΕΔ จࣈྻΛͻ͚ͨΓɺ ෳͷใΛͻ͚ͨΓͰ͖ͳ͍
FOVNͷҰཡΛͱΔ &OVN(FU7BMVFT UZQFPG "OJNBM FOVNʹม int number = (int)Animal.Cat;
FOVNʹม Animal cat = (Animal)number;
FYUFOTJPO
public static class StringExtension { public static string MyUpperCase(this string
str) { return str.ToUpper(); } } TUBUJDDMBTTΛએݴ Ϋϥε໊ԿͰ TUBUJDNFUIPEΛએݴ ୈҰҾʹ֦ு͍ͨ͠ܕͱUIJTΛ͚ͭΔ
string lower = “hello"; lower.MyUpperCase(); طଘͷΫϥεͰϝιουΛՃ͍͚ͯ͠Δ
OVMMBCMF
int? hoge = null; bool? fuga = null; QSJNJUJWFܕʹ͔͔ͭ͑͠ͳ͍ ܕͷલʹ
Λ͚ͭΔ͜ͱͰOVMM͕ೖՄೳʹͳΔ FMWJTPQFSBUPSػೳͱͯ͠ೖͬͯΔ int result = hoge ?? 1; OVMMͩͬͨΒӈͷϦςϥϧ Λબ
$͔ΒA Aಋೖ͞ΕΔͬΆ͍ http://stackoverflow.com/questions/4244225/c-sharp-if-null-then-null-expression
WBS
ܕਪ͕ར༻Ͱ͖Δ$ ͷBVUPʹ૬͢Δػೳ var hoge = "string"; var fuga = 1;
͍͍ͪͪܕΛࠨลͰࢦఆ͠ͳͯ͘ਪͯ͘͠ΕΔ
ಗ໊ܕ
ܕΛએݴͤͣɺϑΟʔϧυʹ҆શʹΞΫηεͰ͖Δ var rem = new { Name = "Rem", Age
= 17 }; var ram = new { Name = "Ram", Age = 17 }; Assert.AreEqual(rem.GetType(), ram.GetType()); 'JFME໊͕ҰॹͳΒܕಉ͡ Debug.Log("Hello, " + rem.Name);
OBNFTQBDF
OBNFTQBDFΛઃఆ͢Δ͜ͱͰ Ϋϥε໊ͷিಥΛආ͚ΒΕΔ namespace My { public class Sample { }
} namespace Other { public class Sample { } }
ଞͷOBNFTQBDFͷΫϥεʹΞΫηε͢Δʹ var sample = new My.Sample(); QSFpYͰOBNFTQBDFΛ͚ͭΔ͔ VTJOHΛͬͯར༻͢ΔએݴΛ͢Δ using My;
1SPQFSUZ
public class Person { private string _name = string.Empty;
public string Name { get { return _name; } set { _name = value; } } } ܕએݴͷޙʹAHFUAATFUAͱ͍͏༧ޠΛͬͯ HFUUFSTFUUFSͷΞΫηε੍ޚ͕Ͱ͖Δ
public class Person { private string _name = string.Empty;
public string Name { get { return _name; } private set { _name = value; } } } TFUUFSΛQSJWBUFʹͯ͠ॻ͖ࠐΊͳͨ͘͠Γɺ HFUTFU͢Δͱ͖ʹԿ͔ॲཧΛهड़ͨ͠Γग़དྷΔ
public class Person { public string Name { get; private
set; } } ୯ʹHFUTFU͢Δ͚ͩͳΒলུه๏͕ར༻Ͱ͖Δ HFUUFSTFUUFS͕ఆٛͰ͖Δ͜ͱͰ,70͕ग़དྷΔͷ͕ 1SPQFSUZͷಛ
1BSUJBM
// Partial Class public partial class SamplePartial : MonoBehaviour {
void Start() { } } public partial class SamplePartial : MonoBehaviour { void Update() { } } AQBSUJBMAΛ͚ͭΔ͜ͱͰ࣮ϑΝΠϧ͕Ͱ͖Δ
ZJFME
foreach (int i in ListupNumbers()) { Debug.Log("number: " + i);
} IEnumerable<int> ListupNumbers() { yield return 0; yield return 1; yield return 2; } -JTUͱ͔"SSBSZΛOFX͠ͳͯ͘ ͜Μͳײ͡ͰZJFMESFUVSOͯ͋͛͠Δͱ ̍ͭͮͭཁૉΛऔಘ͢ΔΑ͏ͳΈ͕؆୯ʹ͔͚Δ
Կ͕ϝϦοτ͔ʁ ཁૉશମΛ֨ೲ͢ΔϝϞϦ͕ඞཁͳ͍ ܁Γฦ͠ཁૉΛऔಘ͢ΔΑ͏ͳॲཧ͕εοΩϦॻ͚Δ
ͲͷΑ͏ʹ࣮ߦ͞ΕΔʁ using (IEnumerator<int> it = ListupNumbers().GetEnumerator()) { while (it.MoveNext()) {
Debug.Log("number: " + it.Current); } } .PWF/FYU Ͱ͖Δ͔͗ΓJUFSBUJPO͕·ΘΔ
JUFSBUJPOΛதஅ͢Δʹʁ IEnumerable<int> ListupNumbers() { yield return 0; yield return 1;
yield break; yield return 2; // ignored } ZJFMECSFBL͢Ε͍͍
6OJUZͷ$PSPVUJOFͱͷରԠ public class Sample : MonoBehaviour { void Start() {
StartCoroutine(ListupNumbers()); StartCoroutine(ListupNumbers()); } void Update() { Debug.Log("Updated"); } IEnumerator<int> ListupNumbers() { for (int i = 0; i < 5; i++) { Debug.Log(i.ToString()); yield return i; } } }
ॳΊ͚ͩ VQEBUF͕ݺΕΔ ͷλΠϛϯάͷ ຖϑϨʔϜ͝ͱʹ A.PWF/FYU A͞ΕͯΔ
PVU
void Increment(out int v) { v = v + 1;
} void Set(out int v) { v = 1; } int i = 0; Set(out i); PVUΛ͔ͭ͏ͱࢀরΛͯ͠มͷॻ͖ࠐΈ͕Ͱ͖Δ ͨͩ͠PVU͕͍ͭͨมͷऔಘͰ͖ͳ͍ ͍ํ ӈลͰWΛར༻ͯ͠ΔͷͰμϝ
-*/2
IUUQXXXTMJEFTIBSFOFUGVNJUBLBZBNBEBDMJOR