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
subpath importsで始めるモック生活
10tera
0
310
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Jakarta EE meets AI
ivargrimstad
0
600
Jakarta EE meets AI
ivargrimstad
0
670
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
flutterkaigi_2024.pdf
kyoheig3
0
150
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
890
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
受け取る人から提供する人になるということ
little_rubyist
0
250
Featured
See All Featured
Done Done
chrislema
181
16k
A Tale of Four Properties
chriscoyier
156
23k
Automating Front-end Workflow
addyosmani
1366
200k
BBQ
matthewcrist
85
9.3k
Building Adaptive Systems
keathley
38
2.3k
How STYLIGHT went responsive
nonsquared
95
5.2k
Become a Pro
speakerdeck
PRO
25
5k
Making Projects Easy
brettharned
115
5.9k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
A better future with KSS
kneath
238
17k
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