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
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
280
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
선언형 UI에서의 상태관리
l2hyunwoo
0
140
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
return文におけるstd::moveについて
onihusube
1
900
CSC509 Lecture 14
javiergs
PRO
0
140
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Invisible Side of Design
smashingmag
298
50k
KATA
mclloyd
29
14k
The Cult of Friendly URLs
andyhume
78
6.1k
Statistics for Hackers
jakevdp
796
220k
Faster Mobile Websites
deanohume
305
30k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
A Philosophy of Restraint
colly
203
16k
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