Building Your First iOS App with Xamarin for Visual Studio
How C# Save My Marriage, Enhanced My Career, and Made Me an Inch Taller, Scott Hanselman
1. Giant Disclaimer
I’m here as me, doing my thing. These opinions are
mine, Scott Hanselman. If I say something stupid and
you’re a journalist, make sure to quote me as
“Scott Hanselman, Stupid Guy.”
I’m not the manager of anything important at Microsoft.
I am a member of the .NET Community. I care.
2. How C#
Saved My Marriage,
Enhanced My Career,
and Made Me
An Inch Taller
Scott Hanselman
@shanselman
3. How C#
Saved My Marriage,
Enhanced My Career,
and Made Me
An Inch Taller
Scott Hanselman
@shanselman
50. ; Do fu so it can be turned into a binary or something
main:
.loop:
; function calls are slow ;-)
mov eax, 3 ; magic number for read()
xor ebx, ebx ; file handle
mov ecx, buffer ; buffer to fill
mov edx, 4096 ; how many bytes to read
int 0x80
; if the program doesn't work, replace ebx with a 0
cmp eax, ebx ; ebx is 0 from the
filehandle (we hope)
jle .done
; now eax contains the # of bytes read.
.rot_buffer:
mov edx, buffer;
mov ecx, table
X86 ASM
51. HAI!
IM IN YR Northwind
HOW DUZ I ListProducts YR id
PRODUCTS = GETPRODUCTS id
OMG FOUND YR PRODUCTS
IF U SEZ
IM OUTTA YR Northwind
LOLCode
54. checked and unchecked
class
Test
{
static
readonly
int
x
=
1000000;
static
readonly
int
y
=
1000000;
static
int
F()
{
return
checked(x
*
y);
//
Throws
OverflowException
}
static
int
G()
{
return
unchecked(x
*
y);
//
Returns
-‐727379968
}
static
int
H()
{
return
x
*
y;
//
Depends
on
default
}
}
55. Evolution of async
Asynchronous
Programming
Model
(APM)
var
request
=
HttpWebRequest.Create("http://www.microsoft.com");
request.BeginGetResponse(result
=>
{
try
{
using
(var
response
=
(HttpWebResponse)request.EndGetResponse(result))
{
//now
it’s
STREAM
READER
TIME
SO
SUCK
IT
UP
AND
GET
TO
WORK
using
(var
stream
=
new
StreamReader(response.GetResponseStream()))
{
//
ZOMG
have
to
write
an
async
read
loop....
}
}
}
catch
(Exception
ex)
{
}
//THERE
IS
MORE
CODE
DOWN
HERE
OVERFLOWING
INTO
ANOTHER
TALK
ANOTHER
DAY
},
null);
56. Evolution of async
Just
Get’er
Done
and
Block
Model
(synchronous)
WebClient
client
=
new
WebClient();
client.DownloadFile("http://microsoft.com",
"index.html");
57. Evolution of async
Event-‐based
Asynchronous
Pattern
(EAP)
var
wc
=
new
WebClient();
wc.DownloadStringCompleted
+=
(sender,
e)
=>
{
//
do
it
here,
be
aware
of
what
thread
you’re
on
};
wc.DownloadStringAsync("http://microsoft.com");
58. Evolution of async
Async
and
await
var
client
=
new
HttpClient();
string
data
=
await
client.GetStringAsync(mscomuri);
63. pho·ny also pho·ney (fō'nē)
adj. pho·ni·er, pho·ni·est
1.
a. Not genuine or real; counterfeit: a phony credit
card.
b. False; spurious: a phony name.
2. Not honest or truthful; deceptive: a phony
excuse.
3.
a. Insincere or hypocritical.
b. Giving a false impression of truth or
authenticity; specious.
64.
65. C# keeps getting better
C#, once high level, can be pretty darn low level
Share code across mobile and cloud
Native native native
NuGet is love!
Generics, Linq, async/await
You have skills/tools/code
Thanks, Stu!
94. Model-View-ViewModel (MVVM)
Views
How to display information
Written in XAML
View Models
What information to display
Flow of interaction
Models
Data objects
Business logic
Etc.
Platform-specific
Portable-ish (DRY)References
Databinds
95. Cross Platform App Architecture
Startup
Views
Windows Store App
Platform specific functionality
View Models
Models
Portable Class Library
Platform functionality abstractions
Startup
Views
Windows Phone App
Platform specific functionality
References References