What Is C# Programming Language?

C# is a language derived from C and C++, but it was created from the ground level. Microsoft started with what worked in C and C++ and included new features that would make C# languages easier to use. Most of these features are very similar to what can be found in Java. Ultimately, Microsoft had a number of objectives when building the language. These objectives can be summarized in the claims Microsoft makes about C#:

• C# is simple.
• C# is modern.
• C# is object-oriented.

In addition to Microsoft’s reasons, there are other reasons to use C#:

• C# is powerful and flexible.

• C# is a language of few words.

• C# is modular.

• C# will be popular.

C# Is Simple

C# removes some of the complexities of languages such as Java and C++, including the removal of macros, templates (in the form of Generic in C# 2.0), multiple inheritance, and virtual base classes. These are all areas that cause either confusion or potential problems for C++ developers.

C# is simple because it is based on C and C++. If you are familiar with C and C++, or even Java, you will find C# very familiar in many aspects. Statements, expressions, operators, and other functions are taken directly from C and C++, but improvements make the C# language simpler.

Some of the improvements include eliminating redundancies. Other areas of improvement include additional syntax changes. For example, C++ has three operators for working with members: ::, ., and ->.

Knowing when to use each of these three symbols can be very confusing in C++. In C#, these are all replaced with a single symbol–the “dot” operator. For newer programmers, this and many other features eliminate a lot of confusion.

Note: If you have used Java and you believe it is simplest, you will find C# to be simple. Most people don’t believe that Java is simple. C# is, however, easier than Java and C++.

C# Is Modern

What features make a language modern? Features such as exception handling, garbage collection, extensible data types, and code security are features that are expected in a modern language. C# contains all of these.

Note: Pointers are an integral part of C and C++. They are also the most confusing part of the languages. C# removes much of the complexity and trouble caused by pointers. In C#, automatic garbage collection and type safety are an integral part of the language

C# Is Object-Oriented

The keys to an object-oriented language are encapsulation, inheritance, and polymorphism. C# supports all of these. Encapsulation is the placing of functionality into a single package. Inheritance is a structured way of extending existing code and functionality into new programs and packages. Polymorphism is the capability of adapting to what needs to be done. Understand, these are very basic definitions. The implementation of these is a bit more complicated.

C# Is Powerful and Flexible

As mentioned before, with C# you are limited only by your imagination. The language places no constraints on what can be done. C# can be used for projects as diverse as creating word processors, graphics, spreadsheets, and even compilers for other languages.

C# Is a Language of Few Words

C# is a language that uses a limited number of keywords. C# contains only a handful of terms, called keywords, which serve as the base on which the language’s functionality is built. Table 1 lists the C# keywords.

A majority of these keywords are used to describe information. You might think that a language with more keywords would be more powerful. This isn’t true. As you program with C#, you will find that it can be used to do any task.

TABLE 1. The C# Keywords
abstract as base bool break
byte case catch char checked
class const continue decimal default
delegate do double else enum
event explicit extern false finally
fixed float for foreach
goto if implicin int
interface internal is lock long
namespace new null object operator
out override params private protected
public readonly ref return sbyte
sealed short sizeof stackalloc
static string struct switch this
throw true try typeof uint
ulong unchecked unsafe ushort using

Note: There are a few other words used in C# programs. While not keywords, they should be treated as though they were. Specifically,

Get        set      value.
virtual   void   while

C# Is Modular

C# code can (and should) be written in classes, which contain member methods. These classes and methods can be reused in other applications or programs. By passing pieces of information to the classes and methods, you can easily create useful and reusable code.

C# Will Be Popular

C# is one of the newest programming languages but it will become a very popular language for a number of reasons. One of the key reasons is Microsoft and the promises of .NET.

Microsoft wants C# to be popular. Although a company cannot make a product be popular, it can help. Not long ago, Microsoft suffered the abysmal failure of the Microsoft Bob operating system. Although Microsoft wanted Bob to be popular, it failed. C# stands a better chance of success than Microsoft Bob. I don’t know whether people at Microsoft actually used Bob in their daily jobs. C#, however, is being used by Microsoft. Many of its products have already had portions rewritten in C#. By using it, Microsoft helps validate the capabilities of C# to meet the needs of programmers.

Microsoft .NET is another reason why C# stands a chance to succeed. .NET is a change in the way the creation and implementation of applications is done. . .Net has been changed the way of creation and implementation of any application. Although virtually any programming language can be used with .NET, C# is proving to be the language of choice. Tomorrow’s lesson includes a section that explains the high points of .NET.

Why you should choose C#

The migration to the .NET platform offers many development options. If you are moving to .NET and you already know about C++ or Java, C# is a logical choice for you. However, if you are undecided about .NET, you might wonder why you’d want to choose to C# rather than your COM-based C++.

Often the decision to move to .NET is based on factors other than learning C#, but C# does offer many advantages over any COM-based language. Here, we explain why C# is an important language and why you should consider moving to C#.

1. Modernized language

C# is a modern version of C++. Originally you had the language C, which was widely used. C++ came about to add object-oriented concept with C, and C++ became the language of building “real” applications for Windows (according to the C++ developers.) C++ was used for writing the infrastructure and low-level applications, while Visual Basic developers wrote business applications.

C# brings the rapid development paradigm of VB to the world of C++ developers, with some noticeable changes. C# takes advantage of the .NET Framework, which means you have access to a powerful forms engine, just like VB developers. New data types have been added, such as the decimal data type for performing financial calculations.

2. Type-safety

C# is type-safe, which means several things. For example, you cannot use uninitialised variables. In C++ it is easy to declare a variable and then check its value; whatever was in the memory address given to that variable would then be shown, and this could inflict confusion on an application. The C# complier will notify you if you try to use a variable before you have initialized it to some valid value.

With C#, you can no longer just walk past the end of an array, as you have been able to do in C and C++. In C++ you could declare an array of three elements and then happily examine the fourth element of that array and get the next portion of memory.

3. Object-oriented

Many people would argue that C++ is object-oriented, C# goes to another level. Even simple data types can be treated as objects, meaning that an int has methods associated with it. For example, you can use the ToString method to get a string value for an int, as shown below.

int Counter=14;
Console.Write(Counter.ToString());

In addition, literal strings can be treated as objects and support a variety of methods, such as Trim, ToUpper, ToLower, and many others, as shown here:

Console.Write(“hello, world”.ToUpper());

4. Simplified syntax

C++ is an extremely powerful language, it has not typically been considered easy. C# attempts to simplify the syntax to be more consistent and more logical while also removing some of the more complex features of C++. For example, C# does away with pointers. As a type-safe language, C# doesn’t allow direct memory manipulation, so pointers are no longer needed in C#.

Header files have also been removed from C#. The namespace and reference operators, :: and -> respectively, have been replaced with a single operator, the period dot(.).

Perhaps one of the biggest changes is that the int and bool data types are now completely different. This means that you will finally have an end to the assignment vs. comparison problem in if statements. In other words, the following code will not even compile under C#:

int Counter=14;
if (Counter=14) { //do something }

Attempting to compile this code will return an error stating: Cannot implicitly convert type ‘int’ to ‘bool’

C# also removes memory management issues from the developer by using .NET’s garbage collection scheme. Items no longer referenced are marked for garbage collection, and the Framework can reclaim this memory as needed.

5. XML comments

C# supports the introduction of XML comments. Far from being just another way to add comments to code, XML comments can actually turn into your documentation. The comments are placed into XML format and can then be used as needed to document your code.

This documentation can include example code, parameters, and references to other topics. It finally makes sense for a developer to document his or her code, because those comments can actually become documentation independent of the source code.

6. Not just Microsoft

C# is not just about Microsoft anymore. Microsoft released C# to ECMA(European Computer Manufacturer Association) and it has been published as an standard. In addition, the Mono project is an effort to make an open source version of the .NET Framework (a subset of it called the CLI) and an open source version of C#, all for Linux.

7. All about components

Creating components is straightforward, as is referencing those components in code. Namespaces in C# replace a lot of the headaches from the COM world in which you had to perform registry lookups and instantiate objects and worry about such things as IUnknown and IDispatch. Using C#, you simply import a namespace and then begin using the classes in that component—no registry lookups or COM plumbing required.

8. The power to be unsafe

Much is made about C#’s type-safety, but if you want to drive without a seatbelt, you are free to do so. If you really need to use pointers, for example, you can use the unsafe keyword to mark a block of code. This allows that code to bypass the Framework’s type-safety checking and means that you can directly manipulate memory. This makes C# incredibly powerful and is one of the advantages of C# over VB.NET.

9. Cross-language capabilities

C# has the ability to allow you to interoperate with any other language on the .NET platform. Much has been said about how you can create a component in one language and inherit and extend that component in another language, which is something that was difficult, if not impossible, with COM.

C# also supports the concept of error handling across different languages. Gone are the unfriendly HResults; instead, you have access to .NET exceptions, which are consistent across any .NET language.

10. It might be worth more

When it comes to creating applications for .NET, the choice between VB.NET and C# is typically not important. However, it is quite possible that companies are willing to pay more for C# developers; C++ developers have typically been harder to find than VB developers and have been better compensated. It’s likely there will be more VB.NET developers than C# developers, so this trend may well continue into the future.

Scroll to Top