C# LANGUAGE

THE C# LANGUAGE

STRUCTURE OF A C# PROGRAM We will see the general structure of a program written with the C Sharp language. LINK TO LIST OF LANGUAGE RESERVED WORDS LANGUAGE RESERVED KEYWORDS These keywords cannot be used as identifiers. THE FIRST C# PROGRAM Let's create a folder and name it Corso C#. I created it under the main Windows directory. THE C SHARP LANGUAGE - OPEN VISUAL STUDIO CODE We open the command prompt and place ourselves in the newly created folder. We type the following command: dotnet [...]

By |2024-07-20T00:04:02+02:0030 April 2021|0 Comments

VARIABLES IN C#

VARIABLES IN C SHARP Variables in C Sharp are areas of memory in which a certain type of data is temporarily stored, they are the fundamental basis of the C# language, a variable can contain data of a type defined in the standard library such as an int (the keyword int indicates to the compiler that we are declaring an integer) or a type introduced by us. To declare a variable proceed as follows: VARIABLES IN C SHARP - DECLARATION int myVar ; With this instruction which as you can see ends with a semicolon as we have seen [...]

By |2024-07-20T10:23:31+02:001 May 2021|0 Comments

DATA TYPES IN C SHARP

DATA TYPES IN C SHARP THE INTEGRAL TYPES C# data .NET data Byte Minimum value Maximum value int System.Int32 4 -2.147.483.648 2.147.483.647 byte System.Byte 1 0 255 short System.Int16 2 -32.768 32.767 long System.Int64 8 -9.223.372.036.854.775.808 9.223.372.036.854.775.807 sbyte System.SByte 1 -128 127 uint System.UInt32 4 0 4.294.967.295 ushort System.UInt16 2 0 65.535 ulong System.UInt64 8 0 18.446.744.073.709.551.615 char System.Char 2 0 65.535 DATA TYPES IN C SHARP THE TYPE CHAR As shown in the table in the data types in C Sharp the integer types can be signed as int, long, short, sbyte and unsigned byte, [...]

By |2024-07-21T00:18:45+02:001 May 2021|0 Comments

CAST AND OPERATORS IN C SHARP

THE OPERATORS CAST AND OPERATORS IN C SHARP THE MATHEMATICAL OPERATORS Suppose we have two variables x and y with the following values: int x = 8 ; int y = 4 ; Operator Description Example + Sum or Concatenation x + y = 12 - Subtraction x - y = 4 * Multiplication x * y = 32 / Division x / y = 2 % Modulo (returns the remainder of an integer division) x % y = 0 ++ Increase x++ = 9 -- Decrease x-- = 7 OPERAND OPERATOR OPERAND     [...]

By |2024-07-21T18:01:02+02:002 May 2021|0 Comments

CONDITIONAL STRUCTURES IN C SHARP

CONDITIONAL STRUCTURES IN C SHARP In programs it often happens that blocks of code are executed when certain conditions arise. Suppose for example, to introduce conditional structures, that our program asks the user his age and based on this decides whether he can drive or not. int age = 0; Console.WriteLine ("Enter your age...."); String eta = Console.ReadLine (); age = Convert.ToInt32 (eta); Console.WriteLine ($"You introduced {age} years."); The piece of code I gave you above asks via a Console.WriteLine to enter the age, then with a Console.ReadLine() which you have never seen yet but which basically does nothing [...]

By |2024-07-22T02:52:35+02:002 May 2021|0 Comments

THE LOOPS IN C SHARP

ITERATIONS IN C# LOOPS IN C SHARP THE WHILE LOOP In C Sharp loops the syntax of a while loop is as follows: while (boolean condition) {     //INSTRUCTIONS } The Boolean condition is a normal expression that evaluates to true or false. It is important to note that if the Boolean condition is false before starting the loop (the condition is checked first) then the while loop will never be executed. While iterates through the block of code enclosed in the braces as long as the condition is true. Let's see an example: byte b = 0; [...]

By |2024-07-23T05:54:53+02:003 May 2021|0 Comments

METHODS IN C#

using System; namespace Metodi; internal class Program { private static void Main(string[] args) { Console.WriteLine("Chiamata a metodo della classe Console."); } } METHODS IN C# C Sharp methods are one of the most important data structures in Object Oriented programming also known as OOP. The function of a method is to enclose code in a block delimited by curly brackets so that it can then be called or, as they say, invoked in other parts of the program. We have encountered a particular method many times, the Main method generated when we create a [...]

By |2024-07-24T09:50:55+02:004 May 2021|0 Comments

VALUE AND REFERENCE TYPES IN C SHARP

STACK AND HEAP In value and reference types in C Sharp when a C# program runs the runtime environment creates two distinct areas of memory, the stack and the heap. Let's start talking about the stack by helping with the program below and the schematization in the figure. THE PROGRAM TO ANALYZE THE STACK namespace StackAndHeap; internal class Program { private static void Main() { var x1 = 10; var result = FirstMethod(x1); } private static int FirstMethod(int a) { var y = 20; int z; z = SecondMethod(y); return z + a; [...]

By |2024-07-28T05:34:44+02:004 May 2021|0 Comments

THE CLASSES IN C SHARP

CLASSES INTRODUCTION With classes in C# we approach the heart of Object Oriented programming also known as OOP. In any object-oriented programming language, classes are fundamental entities. To approach this type of programming we will simulate the management of a checking account. Obviously the real code would be quite different, but to introduce OOP we will focus on this type of example. Now let's see how to declare a class in C#. using System; namespace DefinizioneClasse { class MyClass //DEFINIZIONE DI UNA CLASSE { } class Program { static void Main(string[] args) { } } } [...]

By |2024-07-30T09:01:10+02:005 May 2021|0 Comments

THE PROPERTIES IN C SHARP

PROPERTIES IN C# Properties in C# are the mechanism that the language provides us with to accomplish encapsulation of data. We saw in the previous post how it is possible to encapsulate a certain variable defined within a class, making it private, and implementing two public methods that allow read and write access to the variable from outside, respectively. I report the code: using System; namespace Property { public class Persona { private string nome; public string GetNome() { return this.nome; } public void SetNome(string nome) { //qui ci vanno eventuali controlli prima di assegnare l'attributo [...]

By |2024-07-31T09:00:04+02:005 May 2021|0 Comments
Go to Top