Programming in C#
As already mentioned, some parts in EPLAN were programmed in the .NET platform. This suggests that this is also the programming language used. However, this is not correct, as the core of the EPLAN applications was developed in the C++ language.
The use of different programming languages in software could be compared to the German language. The same language is spoken in Germany and Austria, yet different words are sometimes used for the same term in the two countries.
-
Language:
- US →
Cookie
- UK →
Biscuit
- US →
-
Program code:
- C# →
System.Console.WriteLine("Cookie");
- C++ →
std::cout << "Cookie" << std::endl;
- C# →
Both languages are included in the Microsoft.NET software platform. If these lines of code are now translated (i.e. converted into machine code), the computer does the same. In both cases, the word Cookie is output.
What is .NET?
In order not to go beyond the scope of the book and to keep the complexity low, only the basics that are relevant for programming scripts are explained. With .NET, Microsoft has created a software platform that makes programming easier for developers. The most important features and advantages of .NET include the following:
-
Runtime environment: If we stick to our example with the German language, then the runtime environment refers to all countries in which German is spoken.
-
Class libraries: These contain ready-made functions that you do not have to program yourself.
-
Utility programs: This refers to programs that you can "talk" to.
-
Object-oriented programming
-
Support for multiple programming languages:
- C#
- VB.NET
- C++
- F#
General information about C#
As C# is used in the examples, this language will be discussed in more detail and its origins explained a little. Let's start with the name: C# is pronounced "c sharp" siːˈʃɑːp. Sharp is derived from the sharp in music (a sharp ♯ stands for a note raised by a semitone). As the double cross can be found on the standard keyboard layout, it is used when writing the name. C# was published and released by Microsoft in 2001. It is therefore not yet such an old language (in comparison: C was created in 1972). With C#, Microsoft has copied a lot from other languages or picked out the best.
There are parallels to the following programming languages:
-
C
-
C++
-
Delphi
-
Java
-
Visual Basic
C# is one of the object-oriented programming languages and was standardized in 2003 standardized in 2003 (ISO/IEC 23270). C# is platform-independent from version 5 onwards, which means that a program can also be executed on Linux and macOS, for example. be executed.
What is a development environment?
Since you have to pay attention to many things when programming, such as syntax, program flow etc., there are development environments that support programmers support programmers in writing the code.
Info
The syntax is the way the code is written. Each programming language has its own language usage/structure. The syntax corresponds to the vocabulary and grammar of a spoken language. A compiler is a program that converts the program code of the respective language into machine code. The conversion is called "compiling". The bytecode is an intermediate code from the operating system to the processor.
In order to execute a program, the program code must first be "prepared". The Visual Studio development environment provides a so-called compiler for this purpose. This consists of two parts in the .NET environment. First, the compiler converts the program code into a universal language. All .NET languages are translated into the same language. Then the compiler converts the code into bytecode. The operating system can provide this to the processor in order to execute the program.
flowchart TD
.NET-programming-language --> Compiler-1 --> Universal-language --> Compiler-2 --> Machine-code --> Processor
A development environment can also help programmers to create graphical user interfaces. In the early days of graphical operating systems, these had to be stored in the program code, which was very difficult as all coordinates had to be calculated. Something as trivial as maximizing or resizing a window meant an enormous amount of programming. This amount of code is automatically generated in a development environment when you create a form with only one text field.
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 115);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(260, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "TextBox";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();