Category Archive for: C# Basics

Usage Conventions

In any development language, there usually arise certain traditional programming styles. The styles are not part of the language itself but are conventions concerning, for example, how variables are named or how certain classes, methods, or functions are used. If most developers using that language follow the same conventions, it makes it easier for different developers to understand…

Read More →

C# Programming Guidelines

The final section of this chapter supplies the guidelines you need to bear in mind when writing C# programs. Rules for Identifiers  This section examines the rules governing what names you can use for variables, classes, methods, and so on. Note that the rules presented in this section are not merely guidelines: they are’ enforced by the…

Read More →

The C# Preprocessor Directives

Besides ‘the usual keywords, most of which you have now encountered, C# also includes a number of commands that are known as preprocessor directives. These commands never actually get translated.to any commands in your executable code, but instead they affect aspects of the compilation process. For example, you can use preprocessor directives to prevent the compiler from compiling…

Read More →

XML Documentation

In addition to the C-type comments, illustrated in the preceding section, C# has a very neat feature that we want to highlight: the ability produce documentation in XML. format automatically from special comments. These comments are single-line comments but begin with three slashes instead of the usual two. Within these comments, you can place XML tags containing documentation of…

Read More →

Using Comments

The next topic – adding comments to your code -looks very simple on the surface but can be complex . Internal Comments within the Source Files As noted earlier in this chapter, C# uses the traditional C-type single-line and multiline comments. Everything in a single-line comment, from the // to the end of the line,…

Read More →

Console I/O

By this point, you should have a basic familiarity with C#’s data types; as well as some knowledge of how the thread-of-control moves through a program that manipulates those data types. In this chapter, you have also use several of the Console class’s static methods used for reading and writing data. Because these methods are so useful when…

Read More →

More on Compiling C# FiIes

You have seen how to compile console applications using csc . exe, but what about other types of applications? What if you want to reference a class library? The full set of compilation options for the C#. compiler is of course detailed in the MSDN documentation, but we list here the most important options. To answer the…

Read More →

The Main( ) Method

As you saw at the start of this chapter, C# programs start execution at a method named Main (). This must be a static method of a class (or struct), and must have a return type of either int or void. Although it is common to specify the public modifier explicitly, because by definition the method…

Read More →

Namespaces

As you have seen, namespaces provide a way of organizing related classes and other types. Unlike a file or a component, a namespace is a logical, rather than a physical, grouping. When you define a class in a C# file, you can include it within a namespace definition. Later, when you define another class that performs related work…

Read More →

Arrays

“Arrays.” However, we’ll give you just enough syntax here that you can code one-dimensional arrays . Arrays in C# are declared by fixing a set of square brackets to the end of the variable. type of the individual elements (note that all the elements in an array must be of the same data type). A note…

Read More →

Back to Top