官术网_书友最值得收藏!

Looking for help

This section is about how to find quality information about programming on the Web.

MSDN

The definitive resource for getting help about C# and .NET is the Microsoft Developer Network (MSDN).

Visual Studio is integrated with MSDN, so if you press F1 inside a C# keyword or type, then it will open your browser and take you to the official documentation.

Almost all the reference URLs at the end of chapters in this book will take you to MSDN.

Getting the definition of code

Another useful keystroke is F12. This will show what the original source code looks like. It uses a similar technique as IL DASM to reverse engineer the source code from Microsoft assemblies.

Enter the following code, click inside int, and then press F12 (or right-click and choose Go To Definition):

int x;

In the new code window that appears, you can see that int is in the mscorlib.dll assembly, it is named Int32, it is in the System namespace, and int is therefore an alias for System.Int32.

Microsoft defined Int32 using a struct keyword, meaning that it is a value type stored on the stack. You can also see that Int32 implements interfaces such as IComparable and has constants for its maximum and minimum possible values.

In the code editor window, find the Parse methods and click on the small box with a plus symbol in the Parse methods to expand the code like I have done in the following screenshot:

In the comment, you will see that Microsoft has documented what exceptions might occur if you call this method (ArgumentNullException, FormatException, and OverflowException).

Now we know that we need to wrap a call to this method in a try-catch statement and which exceptions to catch.

StackOverflow

StackOverflow is the most popular third-party website for getting answers to difficult programming questions. It is so popular that search engines such as DuckDuckGo have a special way to write a query to search the site.

Go to DuckDuckGo.com and enter the following query:

!so securestring

You will get the following results:

Google

You can search Google with advanced search options to increase the likelihood of finding what you need.

For example, if you are searching for information about garbage collection using a simple Google query, you would see a Wikipedia definition of garbage collection in computer science and then a list of garbage collection services in your local area.

We can improve the search by restricting it to a useful site like StackOverflow, as shown in the following screenshot:

We can improve the search even more by removing languages that we might not care about, such as C++, as shown in the following screenshot:

Design patterns

A design pattern is a general solution to a common problem. Programmers have been solving the same problems over and over. When the community discovers a good reusable solution, we call it a design pattern. Many design patterns have been documented over the years.

Microsoft has a group called patterns & practices that specializes in documenting and promoting design patterns for Microsoft products.

Tip

Best Practice

Before writing new code, search to see if someone else has already solved the problem in a general way.

主站蜘蛛池模板: 迁安市| 定兴县| 连山| 高清| 张家口市| 宿松县| 增城市| 康乐县| 靖州| 五寨县| 汪清县| 清水河县| 巫山县| 明水县| 广水市| 昭觉县| 怀集县| 嵩明县| 垣曲县| 家居| 威宁| 大厂| 凤冈县| 犍为县| 潼南县| 凤台县| 奇台县| 剑河县| 宜黄县| 延庆县| 成都市| 白城市| 车险| 福安市| 甘谷县| 永安市| 和静县| 西平县| 胶南市| 安康市| 南城县|