Operators in C# programming language

In the previous two posts “Hello C# and .Net Core” and “Do predefined types have different values in .Net Core?”; you first learned how to print some text on a terminal panel, and then you learned how to declare the variables adding some values to them. Show the text on the terminal panel is interesting, but it is not worth it if you do not enter some user data, and assign it to the variables in your program, and use them for your estimate. In this post, we are introducing the basic operators in the C# programming language. We will also say more about other operators, just so you know that they exist, and we will learn them in some other future posts because the beginners in C# program language will be not able to understand it now. There are many things you need to learn to be able to learn all the operators in the C# programming language. So, let’s not rush.

We can assume that you learned some basic operators from elementary school math. It is important to understand that the C# programming language has a lot more operators than you have learned from mathematics. Some operators are the same as those you have learned from math while others exist only in the C# programming language, especially in version 7.0. This means that some of the operators are new and do not exist in the older version of C# programming language. See first what all operator categories exist in the C# programming language in version 7.0. See the picture:

We will start with arithmetic operators. We will start our study of arithmetic operators with a simple small program in which you need to enter two integers. The program should accept user input and execute five arithmetic operations and display results.

(more…)

Continue Reading

Do predefined types have different values in .Net Core?

To answer this question, we will build one Console App .Net Core application in Visual Studio Code installed on Kali Linux distro. The program will introduce us to all types of data, their maximum and minimum values. We will also add a constant to the program and we will see what will get for the results. Then we will check the same code in Visual Studio .Net 2019 Community. But let’s start from beginning. What is programming? Basically, it is a skill for you to tell your computer to behave in a certain way with the code that your computer understands. In order to be involved in programming, it is necessary to have a computer, operating system, Internet connection, IDE – development environment and that you know the certain programming language. In our case, this is C# programming language which we are currently learning. Also, we have Visual Studio Code installed on the Linux operating system and Kali distro installed on an older laptop.

In your case, it may be different. For example, to build .Net Core applications on a different operating system, it’s important to understand that learning C# programming language does not require too many software, hardware and technical costs. Our advice to you is whenever you have an older or less configured computer; install a Linux operating system on it. And use it to learn. In order for your computer to understand your code, you are forwarding commands to your computer in the form of a single line of code or multiple grouped lines of code called statements that the computer understands. You group the statements into methods, methods into classes, and do it as simply, accurately, and without a single mistake. Every piece of code must be without any error, optimized and tested. Also, always try to write the code only once while the same code is used and called repeatedly in the project. But where do the types, variables, their values ​​and constants fit in?

The variables are words that describe a place in memory that contains values ​​that you can change. To understand this, it is best to think of a variable as a small box that stores some value in memory. So, there are various boxes. For example, there is an integer box or an integer type in which you can put an integer value. There is also a decimal box or a decimal type where you can put a decimal value. There is a boolean box that you can only put true or false value. Sometimes you will need to decide is it something true or false. The boolean type is awesome for it. But you can’t put an integer value in a boolean box. So, you put values ​​in specific boxes for that value that store your value in your computer’s RAM – Random Access Memory. This is how the program remembers the data processed.

To control memory usage and data processing speed, you should always consider how much space your variable will use and select the appropriate type for it. But what is a constant? The constant is a special box or special data type that must contain and type. This means that as you create the constant you also specify its type. Variables can change value, but constants cannot. You can add or subtract a number to the variable while the constant is always the same. It is used when you have some value like Pi in mathematics. Its value is 3.14159265359; but lest you constantly write this number whenever you need it in the program; simply create a constant of type Pi of decimal and assign it a value of 3.14159265359. So, when you need this value, you write Pi in your code, while the program knows that the Pi value is the same as if you wrote 3.14159265359. To see how this works, we move on to coding a program that contains predefined types used in the C# programming language.

(more…)

Continue Reading
Close Menu