A Digital Toy C#
Posted On : Aug 04, 2020The C# (c-sharp) which most important achievement of my programming career is more than a programming language to me. I see it as a k'nex or a lego set of my design and programming game like html, css, javascript and sql.
C# is a modern, multipurpose programming language developed by Microsoft company as a simplified version of C language. There are lots of things can be make with C# like desktop-mobile-web based applications, websites, web services and even controlling physical machines. It's widely used in many areas today.
People who interest programming can find some alternative programming languages like php, phyton and java. Although each language has its own advantages or incomplete aspects, you can build almost everything you want with high performance and stability in accordance with your programming experience. It's better to have knowledge on more than one language but i strongly recommend you to do this after you mastered on a language. Otherwise you might be a programmer who has got little knowledge on multiple languages and can not able to build even a simple application. This is the worst thing you may do to yourself at the way of programming. As a result of this kind of action, you can give up on programming and lose your self-confidence by feeling like you can't do anything. Everything has a technique and order in the life, including learning.
I have told that i see the C# language as lego and k'nex sets when beginning to article. As you might remember, these are the toy sets that consists by lots of little parts to build anything by combining them. That's the programming languages are exactly similar to this. They have lots of parts (elements, variables, classes, properties and methods) to build anything you want by using them in a certain scheme. Things you can build are up to your imagination after you got knowledge on how to use these parts.
Although C# codes can be written with any text editor, it's better to use Visual Studio which produced by Microsoft to make these processes easier because of the codes will need to interpreted by a compiler to convert our codes into the machine language. Visual Studio is the best and most used software for C# projects with its very helpful features like intellisense, debugging, project management etc. I'll give detailed information about Visual Studio in another article.
Like in the many programming languages, "variables" are the first things to be learned in C#. Variables are the expressions that represent various types of data assigned to them. They keep these data in temporal memory for later use. Along with variables; namespaces, objects, properties and methods of these objects, and the classes are the most used structures in C#. I'll talk about all of them in my future articles.
You can find the example of a simple console application written as C# below.
// Pre-defined reference classes of variable and objects for usage of programmer. (Added by Visual Studio automatically as default.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// The namespace named as "Sample_Application" which will contain the program codes of our aplication we named as "Sample_Application". (Created by Visual Studio automatically as default.)
namespace Sample_Application
{
// Our program codes will also be inside of a class named as "Program". (Created by Visual Studio automatically as default.)
class Program
{
// Starter function of application which named as "Main" that no returns any value (void), takes a text array (string []) as parameter named with "args" and has a "static" construct to make the codes inside it as reachable from other classes in this application. (Created by Visual Studio automatically as default.)
static void Main(string[] args)
{
// Variable named "a" with integer type and no any value assigned.
int a;
// Variable named "b" with double type and assigned 4.8 value to it.
double b = 4.8;
// "b" variable has been sent to "ToInt32()" function of the "Convert" class as a parameter to be converted into integer type and assigned its value by "=" operator to the "a" variable. If decimal part of the value bigger than 5, assigned value will be one more of original value as integer, otherwise assigned value will be one less as integer. In below example, new value of "a" variable will be 5.
a = Convert.ToInt32(b);
// "Console" class and its "WriteLine" method which writes the value it took as parameter and makes one row down in the console window. Parameters with text format being write between quotes (" "). If quotes are not used, parameter will be considered as variable and system will look its value. If there is not such a variable or variable has not any value, program will throw an error. "+" operator sum the numbers and combines the text values.
Console.WriteLine("a + b = "+ (a + b)); // (a + b) -which inside the parentheses will be considered as numbers.
Console.WriteLine("a + b = "+ a + b); // a + b -which not inside the parentheses will be considered as texts.
// "Console" class and its "ReadLine" method without parameter which makes one row down in the console window and prevents the auto closing of window when program flow is end by waiting user to press any key.
Console.ReadLine();
}
}
}
The screen after running the program. (Output window.)