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
370
UnityC# for Beginner
Presentated in Unity3D study
mattak
June 21, 2016
Tweet
Share
More Decks by mattak
See All by mattak
最近やった作業環境改善施策10個
mattak
0
250
UnixTime is Simple
mattak
0
170
おっさんが停滞しないために
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
770
Unity energy usage
mattak
0
860
Unidux 0.3.1
mattak
1
370
Other Decks in Programming
See All in Programming
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
890
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
770
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
Recoilを剥がしている話
kirik
5
6.7k
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
260
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Site-Speed That Sticks
csswizardry
2
190
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
Building Your Own Lightsaber
phodgson
103
6.1k
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