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
840
Unidux 0.3.1
mattak
1
360
Other Decks in Programming
See All in Programming
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
510
Golang と Erlang
taiyow
8
1.9k
offers_20241022_imakiire.pdf
imakurusu
2
360
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
100
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
830
僕がつくった48個のWebサービス達
yusukebe
18
17k
役立つログに取り組もう
irof
26
8.6k
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
Producing Creativity
orderedlist
PRO
341
39k
The World Runs on Bad Software
bkeepers
PRO
65
11k
BBQ
matthewcrist
85
9.3k
Docker and Python
trallard
40
3.1k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Being A Developer After 40
akosma
86
590k
Git: the NoSQL Database
bkeepers
PRO
425
64k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
A Modern Web Designer's Workflow
chriscoyier
692
190k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
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