Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The C# Programming Language Cheat Sheet, Cheat Sheet of C programming

In this document you have: Origins and Overview, Main Principles and other Features of The C# Programming Language

Typology: Cheat Sheet

2019/2020

Uploaded on 11/27/2020

amritay
amritay 🇺🇸

4.7

(14)

12 documents

Partial preview of the text

Download The C# Programming Language Cheat Sheet and more Cheat Sheet C programming in PDF only on Docsity! The C# Programming Language Juha Kautto, group 93 Origins and Overview The first version of C# was released by Microsoft in the year 2000. The original name during the development was C-like Object Oriented Language (Cool), but ultimately the name was changed due to licensing reasons. It was developed to be used with Microsoft’s .NET Framework, which was launched at the same time. The .NET Framework in turn is an implementation of the Common Language Infrastructure (CLI) standard developed by Microsoft and major hardware manufacturers Hewlett-Packard and Intel. The CLI as well as C# within it are nowadays standardized by International Organization for Standardization (ISO) and European Computer Manufacturers’ Association (ECMA), like other C languages, such as C++ and the original C. The main influence for C#’s design were other C family languages, such as Java and the already mentioned C++. While C# is usually written with a pound sign, the correct symbol is actually the musical note sharp. As its name, spoken as “C Sharp” perhaps implies, it is intended to be a further developed, more simplified version of C++. Other major goal of C# is to be portable. However, since these goals are also shared by Java, the two languages – especially initially – resembled each other a lot. Some subsequent changes to Java were in turn influenced by C#, but in recent years C# and Java have developed in slightly different directions, though. C# is not intended to be competitive with C++ or C in terms of performance or storage use, indicating that the primary target are applications where performance is less critical. Main Principles As C# is strongly derived from other C languages, it has very similar design principles too. Like so many other languages from the last decades the main foundations of C# are that it is structured and object- oriented. This has the aim of making the code easier to read, understand and maintain. The importance of structured and object-oriented languages has grown over time, as programs have grown larger and more complex in design. In C#, objects are instances of classes. Classes are containers, where are defined things that the objects have or use, such as variables and functions, which in C# are officially called methods. A typical simple C# program has classes and the main program, where new instances of the classes are introduced and for example methods are called. In the case of console-based programs, the static main method is always required. The main method has to be static, so that it can be accessible without yet having an instance of the class it is in. Here is an example of a program that prints “Hello, World!” in a console, although needlessly complicated to showcase the class structure: using System; namespace HelloWorld { class Words { public string getWords(string h, string w) { string hw = h + ", " + w + "!"; return hw; } } class Program { static void Main(string[] args) { string hello = "Hello"; string world = "World"; Words wordsObject = new Words(); string helloWorld = wordsObject.getWords(hello, world); Console.WriteLine(helloWorld); Console.ReadLine(); } } } As can be seen, this program has two classes, one of which is called “Program” and holds the Main method. The other class is called “Words” and holds a method that returns a string of two words given to it as input arguments. These two words are in this case defined in the Main method. After that, we see a new instance of the Words class being made, called “wordsObject”. The new instance calls the method from its parent class by giving the two words to it, with the return value being stored in a new string-type variable, called “helloWorld”. Then we use the C#’s built-in “Console” class to write and read the text from a console window that opens when the program runs. The Console class is included in the “System” namespace in the same way the two classes here are included in the “HelloWorld” namespace, both of which can be seen at the top of the code. The System namespace is imported to the program by using the “using” keyword. Even though in this case the separate class and method for parsing together the two words are not really needed, we can already see that the method can take any other words as input arguments as well. The method could be used again, if there was another situation where we needed to piece two words together and insert comma between them. This is called abstraction, instead of making new methods for all slightly different situations, we make fewer that can be used in many of them. Other notes that can be made from the code is that C# is one of the languages that uses curly brackets to mark the start and end of a scope. The brackets are not necessary in some situations, like when using an if statement, leaving out the brackets makes the compiler count one following statement within the scope of the if block, although this is primarily to prevent errors. The use of brackets allows the programmer to shorten the code by fitting some shorter statements on a single line, for example. However, for the best readability, it is recommended to spread all the statements on their own lines. By its core, C# is an imperative language. Although not used in the example above, the data in C# is mutable, which means that for example the value of variables can be changed after the initial value is given. Although mutable data can enable some mistakes from the programmer, it suits the beginner- friendly nature of C# that variables can be freely changed. In recent years, however, the development of C# has taken some influences from functional programming. So, while still an imperative language, C# now also has some features similar to functional languages, like Haskell. One example is the “Func” delegate, which allows a method to take other methods as input arguments. C# also has a rather unique “readonly” keyword, which marks the variable as immutable. The LINQ component, which was introduced in C# 3 as a set of tools for accessing data from various sources such as arrays and XML files, is also heavily based on the principles of functional programming. When talking about type safety, C# can be considered mostly statically or strongly typed language. This is part of why C# is considered a beginner-friendly language, since strong typing allows C# to have good stability with certain amount of automatic error handling. Strong typing also usually makes the code easier to read and maintain. The development environment can also use strong typing to give the programmer more information on for example what kind of things to do with certain types of variables. An example of
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved