Why Use C#

Rumman Ansari   Software Engineer   2019-03-07   5886 Share
☰ Table of Contents

Table of Content:


Why Another More Language?

AT THIS POINT, you're probably asking yourself, "Why should I learn another language? Why not use C++?" (or VB or Java or whatever your preferred language is). At least, you were probably asking yourself that before you coming to this tutorial.

Languages are a little bit like power tools. Each tool has it's own strengths and weaknesses. Though I could use my router to trim a board to length, it would be much easier if I used a miter saw. Similarly, I could use a language like LISP to write a graphics-intensive game, but it would probably be easier to use C++.

C# (pronounced C sharp) is the native language for the .NET Common Language Runtime. It has been designed to fit seamlessly into the .NET Common Language Runtime. You can (and, at times, you should) write code in either Visual C++ or Visual Basic, but in most cases, C# will likely fit your needs better. Because the Common Language Runtime is central to many things in C#, In later Chapter, The .NET Runtime Environment, will introduce the important parts of it at least, those that are important to the C# language.

C# Design Goals

When the C++ language first came out, it caused quite a stir. Here was a language for creating object oriented software that didn't require C programmers to abandon their skills or their investment in software. It wasn’t fully object-oriented in the way a language like Eiffel is, but it had enough object oriented features to offer great benefits.

C# provides a similar opportunity. In cooperation with the .NET Common Language Runtime, it provides a language to use for component oriented software, without forcing programmers to abandon their investment in C, C++, or COM code.

C# is designed for building robust and durable components to handle real world situations.

Component Software

The .NET Common Language Runtime is a component based environment, and it should come as no surprise that C# is designed to make component creation easier.

It's a component-centric language, in that all objects are written as components, and the component is the center of the action.

Component concepts, such as properties, methods, and events, are first class citizens of the language and of the underlying runtime environment. Declarative information (known as attributes) can be applied to components to convey design time and runtime information about the component to other parts of the system. Documentation can be written inside the component and exported to XML.

C# objects don't require header files, IDL files, or type libraries to be created or used. Components created by C# are fully self-describing and can be used without a registration process.

C# is aided in the creation of components by the .NET Runtime and Frameworks, which provide a unified type system in which everything can be treated as an object, but without the performance penalty associated with pure object systems, such as Smalltalk.

Robust and Durable Software

In the component-based world, being able to create software that is robust and durable is very important. Web servers may run for months without a scheduled reboot, and an unscheduled reboot is undesirable.

Garbage collection takes the burden of memory management away from the programmer, and the problems of writing versionable components are eased by definable versioning semantics and the ability to separate the interface from the implementation. Numerical operations can be checked to ensure that they don't overflow, and arrays support bounds checking.

C# also provides an environment that is simple, safe, and straightforward. Error handling is not an afterthought, with exception handling being present throughout the environment. The language is typesafe, and it protects against the use of variables that have not been initialized, unsafe casts, and other common programming errors.

Real-World Software

Software development isn't pretty. Software is rarely designed on a clean slate. it must have decent performance, leverage existing code, and be practical to write in terms of time and budget. A welldesigned environment is of little use if it doesn’t provide enough power for real-world use.

C# provides the benefits of an elegant and unified environment, while still providing access to less reputable features such as pointers when those features are needed to get the job done.

C# protects the investment in existing code. Existing COM objects can be used as if they were .NET objects. The .NET Common Language Runtime will make objects in the runtime appear to be COM objects to existing COM-based code. Native C code in DLL files can be called from C# code.

C# provides low-level access when appropriate. Lightweight objects can be written to be stack allocated and still participate in the unified environment. Low- level access is provided via the unsafe mode, which allows pointers to be used in cases where performance is very important or when pointers are required to use existing DLLs.

C# is built on a C++ heritage and should be immediately comfortable for C++ programmers. The language provides a short learning curve, increased productivity, and no unnecessary sacrifices.

Finally, C# capitalizes on the power of the .NET Common Language Runtime, which provides extensive library support for general programming tasks and application-specific tasks. The .NET Runtime, Frameworks, and languages are all tied together by the Visual Studio environment, providing one-stopshopping for the .NET programmer.