Login

Please fill in your details to login.





c like languages

This page is mainly about c like languages
C, C++, and C# are all programming languages, but they differ in their syntax, features, and areas of application.

C is a low-level programming language that was developed in the 1970s. It is often used for system programming and creating operating systems, embedded systems, and other low-level applications. C is known for its simplicity, efficiency, and speed.

C++ is an extension of the C programming language that was developed in the 1980s. It adds features such as object-oriented programming, templates, and exception handling to the C language. C++ is used for creating large software systems, such as operating systems, compilers, and games. It is also used for high-performance applications, such as scientific simulations and data processing.

C# (pronounced "C sharp") is a modern, high-level programming language that was developed by Microsoft in the early 2000s. It is designed for building applications for the Windows platform and the .NET Framework. C# is a multi-paradigm language that supports object-oriented programming, functional programming, and component-oriented programming. It is used for developing desktop applications, web applications, games, and mobile apps.

In summary, C is a low-level language focused on efficiency, C++ extends C with more features and is used for larger software systems, and C# is a modern high-level language used for developing Windows applications and is multi-paradigm.

Programming in C#


1
Install the .NET Core Development Environment

Download the .NET Core Development Environment > Download (Currently version 7.0)
Run the installer
Open command window
Type
dotnet --version
.NET should respond with a version number, such as
7.0.203
. If it doesn't, uninstall and try again.

Useful DOTNET Console Commands

> dotnet --help {show command line help}
> dotnet --info {display .NET information}
> dotnet --list-runtimes {display the installed runtimes}
> dotnet --list-sdks {display installed SDKs}
> dotnet --version {display .NET version information}
> dotnet new console {create new console application}


2
Install VS Code (lightweight, easy to use)


Create a new console application


Create a folder to hold your project (say 'project')
Open the target folder in VS Code
If the terminal isn't open, choose 'Terminal > New Terminal'
Check that the correct path in the terminal
Type
dotnet new console
and press ENTER
You should see a new folder called
obj
, a settings file,
project.csproj
and the file which contains the code,
Program.cs
.
Click (or double click) to open the
Program.cs
file. You should get a message from VS Code warning you that "Required assets to build and debug are missing from 'project'. Add them?'. Click Yes and you'll see an extra folder called
bin
and a hidden folder called
.vscode
.

For .NET versions below 6.0, the Program.cs is generated with the following template:

using System; // Use code in the .NET system 'namespace'

namespace project // Note: actual namespace depends on the project name.
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!"); // Console object is a terminal in the systen namespace
        }
    }
}


...however, for .NET 6 and above, the template is much simpler...

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");


When you use this newer version, you only need to write the body of the Main method. The compiler synthesizes a Program class with a Main method and places all your top level statements in that Main method. You don't need to include the other program elements, the compiler generates them for you. You can still use the old program structure - the compiler doesn't need to generate the extra elements, is all.

Namespaces


Namespaces help organise programs and present names that are in your code from 'colliding' with names in other programs that you may be using or with names in the .NET programs themselves.

Classes


All C# programs are organised in classes.

The Main function


Each C# console has an entry point and that entry point is named Main. When .NET starts up a program, it looks for the Main entry point and begins execution there. The Main function has no return value (void). The string[] array takes any command line arguments that the app was started with and organises them in an array.

Variable types


int | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647 | int i = 10;
long (8 bytes) Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | long myNum = 15000000000l;
float | 3 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits | float f = 2.0f;
double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits | double d = 19.999d;
bool | 1 bit | Stores true or false values | bool valid = true;
char | 2 bytes | Stores a single character/letter, surrounded by single quotes | char c = 'c';
string | 2 bytes per character | Stores a sequence of characters, surrounded by double quotes | string s = "this is a string";

You can specify the type of variable. For example...

int i = 10;
float f = 2.0f;
decimal d = 10.0m;
bool b = true;
char c = 'c';
string str = "a string";


...although you can also let the compiler figure out what variable type using the var keyword.

var x = 10;
var z = "Hello!";


Arrays


Can be single dimensional, multi-dimensional or jagged
Last modified: July 31st, 2023
The Computing Café works best in landscape mode.
Rotate your device.
Dismiss Warning