Microsoft Visual C# .NET, a new programming language based on Microsoft .NET technology, claims faster and easier development that saves time and money. This article gives an introductory, practical look at programming in C#. To fully utilize the C# language capabilities for test and measurement, you need to have a good understanding of how this language interacts with the Microsoft .NET framework. With a thorough discussion of C# and the object-oriented approach, this article explores how Microsoft C# impacts Visual Studio programming and whether or not it’s right for your test and measurement application development.
The .NET Framework, made up of the Common Language Runtime (CLR), the .NET Framework Class Library, .NET languages, and Visual Studio .NET, supports multiple languages, which allows for cross-platform applications. In order for this to work, a common element must exist through all .NET languages. The Common Language Specification (CLS) is an agreement that encompasses the rules, or specifications, of .NET languages. To be considered a .NET language, a language must comply with specifications set in the CLS agreement. Microsoft provides four CLS-compliant languages, including Visual Basic .NET, Visual C# .NET, Visual C++ with managed extensions, and Jscript. The goals of the CLR are:
The CLR consists of an execution engine, a garbage collector, just-in-time (JIT) compiler, a security system, and the .NET Framework fundamentals.
All of the CLS-compliant — or .NET — languages, have managed code compilers that generate Microsoft Intermediate Language (MSIL). MSIL is machine-independent and can offer benefits including just-in-time compilation, metadata, and more. All .NET applications are constructed from Assemblies, a compiled (and versioned) collection of code and metadata that forms a functional unit. All Assemblies contain information stored in something called a Manifest, which contains the Assembly name, version, dependencies, associated files, and exported features for more informative versioning.
Another feature of Microsoft .NET technology that directly relates to C# is the .NET Framework Class Library. This library consists of more than 2,500 classes whose functionality you can access from all of the .NET languages. The library is made up of four main parts:
C# is a high-level language that hides much of the .NET framework details, while permitting access to system-level functions if the developer needs it. Because Microsoft created C# specifically for .NET, it inherently takes advantage of the .NET Framework features.
C# is an object-oriented language that enables programmers to develop applications with the power of C++ and the ease of Visual Basic. Microsoft built C# from the ground up with the .NET framework and Object Oriented Programming (OOP) in mind. However, C# expands OOP even beyond Visual C++ concepts. It is a strongly typed language in which everything is an object.
The core features of C# were derived from C-like languages. Therefore, if you have experience with C, C++, or Java, you will have a head start in C# development.
C# extends the definition of a object-oriented language from the typical C++ definition. C# unifies the type system by defining every type in the language as an object. Whether using a struct, a class, or an array, the developer will use it as an object. Think of an object as a way to describe a relationship. For a real-world example, think of a ball. A ball has certain characteristics as well as behaviors. A ball has a color, shape, and size that can be thought of as characteristics or variables. A ball also has associated functions, or behaviors, such as bouncing and rolling. Similarly, in C# .NET, objects have characteristics and behaviors.
Classes, the foundation of OOP support in C#, also are important C# elements. Each C# program has at least one class. This class encapsulates data (or variables), and behaviors (or methods). Related classes are grouped into namespaces. This grouping enforces organization and clarity. Objects are combined into namespaces as well. For example, instead of listing include files at the beginning of all of your programs like so:
you would include the namespace to access the classes and objects in the namespace.
(The System class includes output methods)