Looking for help
This section is all about how to find quality information about programming on the web.
Reading Microsoft documentation
The definitive resource for getting help with Microsoft developer tools and platforms used to be Microsoft Developer Network (MSDN). Now, it is Microsoft Docs, and you can find it at the following link: https://docs.microsoft.com/.
Getting help for the dotnet tool
At the command line, you can ask the dotnet
tool for help about its commands.
- To open the official documentation in a browser window for the
dotnet new
command, enter the following at the command line or in Visual Studio Code Terminal:dotnet help new
- To get help output at the command line, use the
-h
or--help
flag, as shown in the following command:dotnet new console -h
- You will see the following partial output:
Console Application (C#) Author: Microsoft Description: A project for creating a command-line application that can run on .NET Core on Windows, Linux and macOS Options: --langVersion Sets langVersion in the created project file text - Optional --no-restore If specified, skips the automatic restore of the project on create. bool - Optional Default: false / (*) true * Indicates the value used if the switch is provided without a value.
Getting definitions of types and their members
One of the most useful keyboard shortcuts in Visual Studio Code is F12 to Go To Definition. This will show what the public definition of the type or member looks like by reading the metadata in the compiled assembly. Some tools like ILSpy .NET Decompiler will even reverse-engineer from the metadata and IL code back into C# for you.
- In Visual Studio Code, open the
HelloCS
folder. - In
Program.cs
, inside theMain
method, enter the following statement to declare an integer variable namedz
:int z;
- Click inside
int
and then press F12, or right-click and choose Go To Definition. In the new code window that appears, you can see how theint
data type is defined, as shown in the following screenshot:You can see that
int
:- Is defined using the
struct
keyword. - Is in the
System.Runtime
assembly. - Is in the
System
namespace. - Is named
Int32
. - Is therefore an alias for the
System.Int32
type. - Implements interfaces such as
IComparable
. - Has constant values for its maximum and minimum values.
- Has methods like
Parse
.Good Practice: When you try to use Go To Definition you will sometimes see an error saying, No definition found. This is because the C# extension does not know about the current project. Navigate to View | Command Palette, enter and select OmniSharp: Select Project, and then select the correct project that you want to work with.
Right now, the Go To Definition feature is not that useful to you because you do not yet know what these terms mean.
By the end of the first part of this book, which teaches you about C#, you will know enough for this feature to become very handy.
- Is defined using the
- In the code editor window, scroll down to find the
Parse
method with a singlestring
parameter starting on line 86, as shown in the following screenshot:
In the comment, you will see that Microsoft has documented what exceptions might occur if you call this method, including ArgumentNullException
, FormatException
, and OverflowException
. Now, we know that we need to wrap a call to this method in a try
statement and which exceptions to catch.
Hopefully, you are getting impatient to learn what all this means!
Be patient for a little longer. You are almost at the end of this chapter, and in the next chapter you will dive into the details of the C# language. But first, let's see where else you can look for help.
Looking for answers on Stack Overflow
Stack Overflow is the most popular third-party website for getting answers to difficult programming questions. It's so popular that search engines such as DuckDuckGo have a special way to write a query to search the site.
- Start your favorite web browser.
- Navigate to DuckDuckGo.com, enter the following query, and note the search results, which are also shown in the following screenshot:
!so securestring
Searching for answers using Google
You can search Google with advanced search options to increase the likelihood of finding what you need.
- Navigate to Google.
- Search for information about
garbage collection
using a simple Google query, and note that you will probably see a Wikipedia definition of garbage collection in computer science, and then a list of garbage collection services in your local area, as shown in the following screenshot:
- Improve the search by restricting it to a useful site such as Stack Overflow, and by removing languages that we might not care about such as C++, Rust, and Python, or by adding C# and .NET explicitly, as shown in the following search query:
garbage collection site:stackoverflow.com +C# -Java
Subscribing to the official .NET blog
To keep up to date with .NET, an excellent blog to subscribe to is the official .NET Blog written by the .NET engineering teams, and you can find it at the following link: https://blogs.msdn.microsoft.com/dotnet/