>> Hello everybody, welcome to the next video in our series.
My name is Cody, I'm
a Visual Studio for Mac Program Manager here at Microsoft.
Today, I'm going to show you how
to get the most out of your editor,
with Code Suggestions and Refactoring,
powered by Roslyn within Visual Studio for Mac, let's get started.
First, we're going to create a new.NET Core project.
To do that, click on "New Project" Navigator to.NET Core,
and click "Console application,
" Think of a great name and go ahead and click "Create".
Now, that our project is open,
let's make some mistakes.
First, I'm going to misuse the variable.
Let's see what happens when I click on the "Value."
We get a nice little eyeball pop up,
with the area indicator.
We have some fixes available to us.
Since I wrote an int,
but typed it as a string,
we can change this to local variable type, Var.
Let's click that and see what happens.
Awesome, it change into a Var,
and now will be typed as an integer.
But it's still not perfect,
there's still a little squiggly line here,
so let's see what that's all about.
Let's click on that light bulb
with the symbol again and see what we can do.
Here, we remove unused variable.
But I might use it,
so let's just skip that for now.
So, let's do int meow equals cat plus 5, perfect.
Now, we see that the variable warning goes
away and we have a nice statement here.
Now that's all fixed up,
let's see what else we can do with Roslyn.
Let's say I wanted to start using a new technology,
but I don't quite remember exactly how to do it.
So, here I'm going to say file.open,
and I notice that there's a squiggly line under file,
with the light bulb and error message.
So, let's click on this and see what we can do.
We have several options including using system.IO.
This is the import that I want to use
to make sure that file that opening is working.
So, click on that and it populates up here.
But I decided not to do this,
let's close that out, delete it.
You see this went to a faded color,
so we go up here click on the "Wrench",
we can now remove unnecessary usings,
this is very powerful if you want to keep your code nice and trim.
So, equivalently remove unnecessary usings
and organized system yourself.
Let's see what else we can do with Roslyn.
I pre-copied some code to make this a
little smoother, let's paste it in.
Here you can see I'm declaring a daytime and extending that value.
This is a little verbose.
So, let's see what Roslyn has to make this better.
Click on "Date" go to the "Wrench" and see what we can do.
Here, we can join the declaration statement.
As brevity is appreciated in code,
this really makes for a better experience.
Let's not stop there, let's see
what other options we have available to us.
Again I'm going to paste in some code,
and see which suggestions it gives us.
Here we have a method which returns a string,
it looks messy, not super organized,
let's see how we can get out of this.
Click on the "If Statement" go over
to the "Wrench" and checks thee suggestions.
Here we can see we should add braces,
so it was a good idea, let's see how it works, perfect.
Organized code is happy code. Let's see what else we can do.
Once again I pre-copied some code,
so I'm going to paste it in here,
I'll delete this and paste in my code.
This is a simple, string format statement,
where you take an integer,
places it in the middle of the string and then return the result.
Let's see what we can do with
Roslyn to make this a little bit simpler.
Click on the "Format" click on the
"Wrench" and we see that we can
convert this to interpolated string.
By doing this, we have
a much simpler statement that's easier to read and understand.
Now, there's one more fix that I want to show you.
Once again I pre-copied some code, so let's paste it in.
Here we have a list declaration,
but there's a few things wrong with this.
First, as you can see,
we have not declared
a using statement for System.Collections.Generic.
Once again click on the error message or air light bulb,
and see the using statement populate.
But now, it's not quite what we want,
this little verbose, little too many words,
let's see if we can fix that.
Here we have, I click on the "List Declaration. "
Collection initialization can be simplified, simplify it then.
Perfect, a lot simpler,
lot easier to read,
and better code all around.
In this video, I showed you how to get
the most Visual Studio for Mac,
by using Quick Actions and suggestions powered by Roslyn.
But let's not stop there,
go ahead download a copy of Visual Studio for Mac,
and see what suggestions it has for your code.
These can make your code simpler,
cleaner, and easier to read.
Please, stay tuned for the next video in our series,
and thank you for watching.
[MUSIC]