►
From YouTube: C# 7 Features with Mads Torgersen
Description
Mads Torgersen takes us on a quick look at some C# 7 features by refactoring a fibonacci series generator.
Here's the code: https://github.com/CodeConversations/csharp7-features-with-mads-torgersen
A
B
Who
hasn't,
and
so
it's
just
a
good
vehicle
for
showing
some
sure
sure
so
see,
chef
Sevan
has
a
bunch
of
features
that
kind
of
go
into
this,
the
small
of
your
programming
they
deal
with
how
your
data
flows
and
how
your
code
flows
and
kind
of
cleans
it
up
in
sort
of
the
programming
in
a
small
kind
of
way.
If
you
will
okay,
so
let's
start
out
with
computing
some
Fibonacci.
So
Fibonacci
is,
as
you
know,
it's
a
function
that
takes
this.
It's
a
sequence
of
numbers,
so
we're
gonna.
B
If
I
can
spell
Fibonacci
here,
you
know
the
nth.
Fibonacci
number
is
computed
by
being
it's
a
sum
of
the
two
previous
one,
all
right,
so
that's
easy.
But
to
do
that
efficiently,
you
don't
want
to
call
recursively
twice,
and
so
you
want
to
have
a
helper
function.
That
gives
you
the
two
previous
ones
right.
Okay,
so
let's
write
that
helper
function
and
talk
about
what
it
should
return,
I'm
just
going
to
put
int
there
for
now.
B
A
B
We
just
wanted
to
make
it
really
easy
to
return
multiple
results,
and
so
now
we
have
two
poles
in
c-sharp
that
look
like
this
hooray
and
you
know
there
can
be
different
types,
but
here
they're
two
ends.
So
this
is
just
this
thing
here
is
just
a
type
that
means
I
have
two
inch
for
you
and
they're
in
a
sequence
in
order
right
right,
I
can
also
make
it
a
little
nicer.
B
I
can
give
them
names,
but
that's
optional,
so
I
could
call
this
one
current
and
this
one
probe
for
just
four
the
guys-
and
this
is
a
high
minus
one,
so
you
can
put
names
on
and
that
makes
them
nice
to
use.
So
that's
a
tubal
type
right
there,
and
so,
if
we
deal
with
the
base
case
of
the
of
the
recursion
here,
if
it's
0
return,
1
comes
0
is
the
first
tuple
and
want
to
return
so
that
it's
a
tuple
literal,
that's
great,
okay,
so
just
super
nice
support
there.
B
It
does
rely
on
a
new
underlying
type
called
value,
tubal,
okay,
that
will
be
in
future
frameworks.
But
if
you're
not
targeting
one
of
those,
yet
we
can
get
this
NuGet
package,
you
can
go,
get
okay
and
then
it's
all
supported.
Okay.
So
so,
let's
let's
implement
this
function.
We
have
so
that
was
the
base
case.
So
if
you're
not
in
the
base
case,
we're
gonna
ignore
negative
numbers.
You
exercise
to
the
reader
right.
A
B
But,
let's
let's
say
otherwise:
let's
get
the
result
of
the
previous
Fibonacci,
so
our
T
for
tuple
equals
fib
of
I
minus
one,
and
we
can
see
what
that
looks
like
and
looks
like
we
T
here.
You
can
see
it's
a
tuple.
It
has
the
current
probe.
Let's
return
a
new
tuple
consisting
of
cheese
current
like
the
previous
current
I'll.
Add
it
with
the
previous
previous,
that's
the
new
two
Bonacci
number
and
then
the
current
one
from
before
is
you
know
going
to
be
the
previous
one?
B
A
B
And
you
see
how
the
nice
names
came
in
handy
here:
I
can
use
them
to
draw,
and
otherwise
there's
a
default.
The
item
one
and
item
two
I
can
use
okay
right.
So
if
you
want
to
implement
the
Fibonacci
method
itself
here,
I
can
return
a
call
to
my
helper
method
with
N
and
then
just
dot
and
get
the
crash
on
here
and
I'm
done.
Wow,
okay,
so
that's
one
way
to
consume,
to
produce
and
consume
tables.
B
There's
also
support
for
culty
construction
was
Cokely
construction,
and
that
means
right
here,
for
instance,
where
I'm
grabbing
a
tubule
and
then
dotting
into
it
later.
Instead
of
having
that
temporary
tubule
value,
I
can
actually
split
the
tubule
I
get
back
from
fib
directly
into
its
components.
B
Too
well
depends
on
the
situation.
I
can
also
I
could
also
do
it
down
here
it.
This
is
actually
a
pretty
nice
implementation.
Just
for
the
sake
of
illustration,
you
know,
let's
pull
this
call
out
to
a
temporary
using
one
of
the
nice
new
refactorings
introduced,
a
local
call
it
R,
but
in
but
then,
let's,
let's
actually
deconstruct
here
and
say
we
want
the
first
component
to
be
the
result,
we're
going
to
return
and
the
second
component.
We
actually
don't
care
about.
We
can
use
this
new
thing
called
a
discard
yeah.
B
A
B
A
B
Not
going
to
show
you
that
here
so
so
on
from
that,
one
thing
they
notice
here
is
that
this
fit
method
is
completely
just
help
a
method
of
the
Fibonacci
and
it
doesn't,
and
nobody
else
should
use
it,
and
so
it
really
should
it
really
belongs
to
inside
of
the
Fibonacci
method.
If
you
will
right
and
so
I
can
actually
now
take
it
and
move
it
into
the
Fibonacci
method,
let's
move
it
to
the.
B
Move
a
piece
of
code
through
other
codes:
okay,
I
love
that
one
for
demo
and
actually
use
it
in
coding
as
well.
Okay,
so
I
can
do
this.
Put
it
in
here
and
put
a
line,
and
you
only
thing
you
see
here
is
that
static
is
underlined,
but
I
tried
to
leave
that,
because
you
can't
put
a
static
modify
in
here.
I
now
have
a
method
defined
inside
of
another
method
and
that's
totally
fine.
That
makes
it
very
clear
that
this
is
only
intended
for
use
inside
of
the
Fibonacci
method.
It's.
B
Yeah
I
could
put
it
anywhere
a
lot.
Okay,
it
doesn't
matter
much.
The
only
thing
is
that,
because
it's
inside
it
can
actually
just
like
a
lambda,
it
can
actually
reference
things
that
are
in
scope
from
the
outer
method.
Right,
if
I
wanted
to
I
could
take
the
the
end
parameter
up
here
from
the
outer
method.
I
could
use
it
inside
of
the
inner
method
and
right,
and
so
you
still
have
to
follow
the
rule
that
you
can't
reference
a
local
before
it's
declared
right.
A
B
A
B
B
It's
actually
being
pretty
smart
about
it.
Let's
change
this
back
to
C,
so
it
actually
implements
Fibonacci.
That's
a
local
function,
Wow,
okay,
okay!
So
now
it
gets
a
little,
let's
say
a
little
far-fetched
here,
but
let's
say
that
I
want
to
change
my
frequency
method
to
a
try
Fibonacci,
where
I'm
getting
any
old
object
as
input
rather
than
an
int,
so
I
get
object
o
instead
and
that
might
fail
because
that
might
not
be
is
for
an
integer
in
any
run
anyway.
B
So
what
I'm
going
to
do
instead
is
follow
the
try
pattern,
I'm
going
to
return
true
I'm,
going
to
wish
I'm
going
to
return
a
bool
and
then
I'm
going
to
have
an
out
like
in
the
old
days
for
the
actual
result.
Okay
out
inch
r4
result
here.
Okay,
so
we
have
to
change
the
method
a
little
bit
now,
that's
already
in
so.
Let's
say
we
already
succeed
and
we
found
an
N.
B
We
we
now
already
have
an
R
variable
that
we
can
just
assign
in
the
deconstruction
here
and
then
we
return
true,
assuming
that
we
succeeded,
but
we
haven't
succeeded
yet
so,
let's
go
and
let's
go
and
see
if
we
can,
if
there's
a
number
n
that
we
can
take
the
Fibonacci
on
here
and
that's
where
we
introduce
the
notion
of
pattern
matching.
So
what
I'm
going
to
do
here
is
to
say
this
object.
If
it's,
you
can
already
do
this
in
c-sharp.
B
If
it's
an
int,
you
know
we're
in
business
mm-hm,
but
now
previously
in
c-sharp,
you
have
now
lost
the
value
as
an
int
and
you
kind
of
have
to
go
figure
grab
it
all
over
again.
Right
now
you
can
add
a
little
n
here,
a
variable
name
to
its
expression
and
that
actually
captures
that
int
that
you
found
out
that
it
was
okay
and
it's
not
just
a
little
extension
of
this
expression
itself.
The
thing
here
in
this
expression
is
now
an
example
of
a
pattern.
B
A
pattern
is
this
new
thing
that
we
allow,
in
c-sharp
known
from
functional
languages,
for
instance,
that
it's
sort
of
a
thing
to
represent
a
test
and
an
extraction
of
data
at
the
same
time.
So
this
is
an
example
of
a
type
pattern
that
tests
whether
the
thing
is
an
int
and
extract
the
int
value.
If
you,
okay,.
B
Both
some
that
we
have
in
c-sharp
now
and
some
that
we
plan
to
add
in
the
future
okay
and
patterns
can
also
be
used
in
switch
statements
by
the
way
and
so
in
greatly
enhance
the
expressiveness
of
switch
statements.
You
come
in
with
this
object,
and
you
you
have
a
case
that
says
this
is
an
if
so
call
it
in
and
go
through
this
key
right.
B
But
so
for
now,
let's
just
do
this
and
put
curly
surround,
so
we
can't
capture
the
whole
two
statement
thing
there
and
now
we
we
declared
in
inside
of
the
is
expression,
and
we
can
use
it
in
here
and
it's
just
like
any
old
variable.
It's
just
declared
inside
of
an
expression,
so
we
could
actually
use
it
and
assign
to
it.
If
you
wanted
to,
let's,
let's
make
this
a
little
more
fun
and
then
say
hey
if
it's
a
string,
if
oh
is
string
s
and
we
can
parse
that
string
as
an
end.
Let's.
B
Say
in
to
try
parse
of
that
string
and
it
needs
an
out
parameter
because
this
again
the
try
pattern,
we
have
the
N
over
here
that
the
integer
that
we
want,
so
we
can
just
Pat
in
as
an
out
parameter,
get
it
assigned
to
by
the
try
parse
and
now
either
way
we
obtained
an
integer
that
we
are
now
writing
to
either
okay
I
see,
which
is
so
that's
a
little.
It's
a
little
tricky
there,
but
yeah
it's
a
it.
Just
shows
how
it
alt
and
click
together
nicely.
B
So
so
there's
your
fifth
method
with
some
pattern
matching
in
it.
It's
it's
a
little
annoyed
that
we're
not
returning
in
all
paths.
So,
let's
add
a
default.
Behavior
result
is
zero
and
we
return
a
false
and
then
it
that
should
shut
it
out.
Wow,
that's
most
of
it.
I
want
to
share
one
more
thing
so
now
we're
starting
to
introduce
variables
in
the
middle
of
expression,
and
we.
A
B
B
We
in
app
for
out
parameters,
we
let
you
declare
a
variable
here.
Let's
call
it
r4
result,
so
the
variable
is
declared
right
here,
where
the
up,
framers
and
and
then
gets
assigned
you
know
by
the
by
the
colleague
and
because
it's
passed
as
a
parameter.
It
actually
even
knows
what
type
it's
supposed
to
be.
You
can
see
from
the
method
signature,
so
we
can
just
put
var
here,
oh
and
right,
it's.
A
B
Long
tightening,
not
only
do
you
avoid
having
to
have
a
separate
name
or
your
separate
line
where
you
declare
it,
but
you
also
avoid
typing
out
the
long
name,
because
you
can
now
just
pick
up
the
type
from
the
out
call
that
you
were
meaning
to
to
do
all
along
alright.
So
now
we
can
just
write
line
it
out,
and
hopefully,
if
I
did
everything
correctly
through
press
ctrl
f5
here
built-
and
it
very
well-
produces
the
Fibonacci
of
eleven.
So
okay,
apparently
weren't
wow.