Postagens

Mostrando postagens de janeiro, 2020

Increment and decrement operations

English: Increment and decrement operations Since you know how add +1 to numerical variables, I am able to show you how do that in a different way using increment statement. Incrementing one unit from variable within this syntax: variable++; This increment operation is called post increment, which this variable is incremented by one. Eg: int myVariable = 20; myVariable++; Console.WriteLine(myVariable); // Output will be 21. But, if you try: int x = 2; int y = x++; The Output from "y" will be 2 and from "x" will be 3. Post increment only add +1 for that variable, but doesn't return this value. Look at the code below: int a = 5; int b = a++; int c = a++ - b++; What is the Output from all of these variables after increment operations? Think a little about this question and then check out the answer: The output from "a" variable is 7, because on second and third line, it is incremented.

Assignments Operators

English: Try it yourself to think about one solution to add +1 value to a variable without losing its current value. Do you know how does do that? Simple: add the self value from variable and then plus 1: int variable = variable + 1; "variable" receives its current value and plus one. If "variable" equals 5, now it is 6. As the same way, you are able to do this operation with subtraction and other arithmetics operations: int a = a - 5; int b = b * 20; int c = c / b; int d = d % 2; In C# we have assignments operators besides of "=", to write the operations above, but being a better syntax, check out below: int number += 10; // As the same that: number = number + 10 int a -= 20; // Same as: a = a - 20 int b *= 5; // b = b * 5 int c /= 40; // c = c / 40 int d %= 7; // d = d % 7 Português-BR: Tente você mesmo pensar em uma solução para adicionar +1 ao valor de uma variável sem perder o valor atual. Voc

Aritmethic Operations

English: Since you are using numerical variables, these data types has normal number properties, as math operations. The operations are: Sum + Subtraction - Multiplication * Division / Module % (Is not percentage) Example: int a = 10; int b = 22; int result = a + b; // Output from result is 32. You can also sum float and double variables, not only ints. Other operations: int num = 500, num2 = 200;  int resultSub = num - num2; // Output from resultSub = 300 * AN ALTERNATIVE WAY TO DECLARE VARIABLES IN C#, IN LINE COMMAND, WHEN EACH VARIABLE TO BE DECLARED ARE THE SAME DATA TYPE. int d = 4, e = 10; int f = d * e; // Output 40 int f = 50, g = 2; int h = f / g; // Output 25 int l = 2017, m = 17; int n = l % m; // Output 17 You can write a numerical expression: int result = 16 % 2 + 9; Or more complex: int result = 10 + 22 - 78 / 2 + 8 * 5; Numerical expression in programming is the same math, mul

Variable

English: Variable Storage values is normal practice while you are programming. Remember about the example when our code checks the user's age. The user should enter this information (Input) and code will execute the verification about that data. But... Where this value (age) will be storaged after user's input? To storage values in code, the world of progammation has one principle called variable. Variables are memory spaces in your computer that can "hold" or "storage" values. Think about one shelf with some boxes and inside of these boxes theres random things. Memory space on your computer is the shelf, boxes are variables and storage inside (things) are values to use. If you want to something inside box, you can open it up and get that thing. This You know where find that box. Then, analogy, if you want use some value in your code, you can store it in variable and can recover it to use after. To declare a variable you must def

Comments

English: Comments Comments in your code are more useful when you need to note something about that code line. To comment in your code in C#, just use these two bars // Example: // Require to users entering his gender Console. Writeline ("Enter your gender"); The compiler ignores comments statements, is like doesn't exist. If you comment statements in C#, the compiler won't read it: // Console. ReadLine (); Nothing happens in the code above. You also comment on more than one line, just use /* */ syntax: /* Console. WriteLine ("I'm being ignored by compiler"); Console. WriteLine ("I was ignored too"); Console. WriteLine ("What is here won't go appear in Console"); */ Console. WriteLine ("I'm running in console, that is great!"); Português-BR: Comentários Os comentários no seu código são úteis quando você precisa anotar algo sobre determinada linha de código

Input and Output

English: Input and Output: One of the most important concepts about programming is the way how any data is inserted into your application and how these information or other information about your program will be returned to the user. These two concepts are called Input and Output. Process to insert values to data inside an application is called Input. It's very normal you input values to applications. For example, when you fill out the form with your data as Name, Gender, School, you are inputting data into an application. Another process is called Output, when the application shows or return to the user, data from it. For example? When you use calculator application and enter 2+2. The output from this input operation is 4 and that result is shown to you. Natively by .Net and C# library these two operations (Input and Output) can be done through two commands: Console. WriteLine () --> This statement is useful when you want to Output to user in Console.