• We just launched and are currently in beta. Join us as we build and grow the community.

Learning to program in C#

ueeyyy

Permissions Master
U Rep
0
0
0
Rep
0
U Vouches
0
0
0
Vouches
0
Posts
135
Likes
139
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In order to take a bit of knowledge of C # (C-Sharp) to beginners in programming, I am starting a new series with a focus on learning about the language in which newcomers to programming track and learn to program in C #.
We will address some basic information about the language such as syntax, data types, variables, operators, flow control, and repeat loops.
1. Introduction
C # (C-Sharp) is a programming language object-oriented and strongly typed created by Microsoft and with the main developer Anders Hejlsberg (the same creator of Delphi and Turbo Pascal) as part of the .NET Framework that is currently in the version 5.0. It is a language influenced by C ++, Java and Object Pascal. I recommend Visual Studio program to program in C#.
2 - Syntax
A code in C # will always be stored in a file with extension ".cs" such as FolhaDePagamento.csou ConexaoDados.cs. Within the C # files, or you can have multiple namespaces and within any one or more of these classes. Let a few examples.
namespace Br.EGH.MeuNamespace
{
public class FolhaDePagamento
{
public FolhaDePagamento()
{
}
}
public class ConexaoDados
{
public ConexaoDados()
{
}
}
}
namespace Br.EGH.OutroNamespace
{
public class Faturamento
{
public Faturamento()
{
}
}
}
In a C # class, we can use some access modifiers such as public or internal
  • public: Esse modificador quando definida na classe a torna acessÃvel publicamente, ou seja, não existe restrição para acesso a classe.
  • internal: Ao aplicar esse modificador a uma classe, essa passa a ser acessÃvel somente dentro do mesmo arquivo do nosso assembly, ou seja, nenhum outro poderá ter acesso a classe.
    3 - Types of data
    Now that you know a bit of the structure of a C # file, we will see the types of existing data. As I mentioned earlier, C # is a strongly typed language and has some data types that can be used to declare the type of our variables.
    Name Class.NET Size Break byte Byte 8 0 a 255 sbyte SByte 8 -128 a 127 int Int32 32 -2147483648 a 2147483647 uint Uint32 32 0 a 4294967295 short Int16 16 -32768 a 32767 ushort UInt16 16 0 a 65535 long Int64 64 -922337203685477508 a 922337203685477507 ulong UInt64 64 0 a 18446744073709551615 float Single 32 -3,4 x 10^28 a 3,4 x 10^38 double Double 64 ±5,0 x 10^-324 a ±1,7 x 10^308 char Char 16 bool Boolean 8 true or false object Object string String decimal Decimal 128 (-7,9 x 10^28 a 7,9 x 10^28) / (10^(0 a 28))
    4 – variables
    To create the variables, it is important to follow some basic rules in time to give a name to them:
    Do not use reserved words in C #: while, for, if, the, event, etc ...
    Not allowed special characters, spaces
    Only use _ or letters or numbers
    Obligatorily should start with _ or letters
    The variable name must be unique in the context that it is declared.
    We go to some sample variable declarations:
    code:
    int contador = 890 ;
    double preco = 3210.74D ;
    bool existe = false ;
    string site = "nulled.to" ;
    5 –Operators
    Operators are terms and symbols used in an expression.
    category operators primary x.y, f(x), a[x], x++, x–, new, typeof, checked, unchecked, default(T), delegate, sizeof, -> unary +x, -x, !x, ~x, ++x, –x, (T)x, await, &x, *x arithmetic x * y, x / y, x % y, x + y, x – y Shift (Exchange) x << y, x >> y relational x < y, x > y, x <= y, x >= y, is, as equality x == y, x != y logical x & y Exclusive or logic x ^ y or logic x | y And Conditional x && y Or Condicional x || y Condicional ?: assignment x = y, x += y, x -= y, x *= y, x /= y, x %= y, x &= y, x |= y, x ^= y, x <<= y, x >>= y Null-coalescing ?? Lambda => As I know the operators, we use a few:
    Código:
    /*arithmetic Operators*/
    int x = 6 * 5 / 3; // result = 10
    int y = 9 + 8 * 14; // result = 121
    int z = 15 % 7; // result = 1
    7- Control Flow
    They are instructions that control the flow of execution of the program under certain conditions. Without them the code is executed from beginning to end without respecting any conditions. Are they:
    • if: It is used to check whether a condition is true. This is using in conjunction with some of the previously mentioned operators.
    • else: It is used when the condition tested if the control is not true. This can also be used in conjunction with if
    • switch: This flow control to set a parameter passed by comparing it with existing conditions and directs the output to one. When there is no condition, it directs to a standard output.
    code: int x = 2 * 3;
    int y = 15 / 3;
    if (x >= 6)
    {
    // Execute a statement any
    }
    if (y > 10)
    {
    // Execute a statement any
    }
    else
    {
    // Execute a statement any
    }
    switch (x % y)
    {
    case 0:
    // Execute a statement any
    break;
    case 1:
    // Execute a statement any
    break;
    default:
    // Execute a statement any
    break;
    }
    8. Repeat Ties
    Repeating loops or the loops as they are commonly known, are instructions of interaction that can perform a certain number of times or while a condition is not satisfactory or even until he is interrupted.
    • do:It runs as a certain condition is not met
    • for:It is performed a number of times
    • foreach:It is run on top of an array or collection, i.e., through all the elements
    • while: It runs as a certain condition is not met
    code: /*IMPLEMENTATION EXAMPLE WITHLOOP "do" */
    int x = 0;
    do
    {
    Console.WriteLine(x);
    x++;
    } while (x <10);
    /* IMPLEMENTATION EXAMPLE WITH "for" */
    for(int y = 0; y < 10; y++)
    {
    Console.WriteLine(y);
    }
    /* IMPLEMENTATION EXAMPLE WITH "foreach" */
    int[] l = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    foreach(int i in l)
    {
    Console.WriteLine(i);
    }
    /* IMPLEMENTATION EXAMPLE WITH "while" */
    int z = 0;
    while (z <10)
    {
    Console.WriteLine(z);
    z++;
    }
    Up here you could see the basics of C #, thank you for reading and until next.
 

440,010

316,559

316,568

Top