Google+
Join free weekly webinars
Find us on
Back

C# Startup

Tags: snippets, C#

 

EventIDE provides the full-features C# language for scripting in experiments. C# 4.0 is a modern programming language combining the power of C++ and the simplicity of Python and Basic. Recently, C# has become one of the most popular languages among professional developers for Windows. However, you do not need to explore all advanced techniques, because in EventIDE scripting is necessary only to control the runtime scenario. it does not require special programming skills and learning new function and procedures.

To help you with a quick startup with C#, we created this guide. It covers the most common programming practices that you may need in EventIDE. The guide consists of the quick syntax code examples and a collection of the useful C# web links. You can send us your suggestions on what can be added in the guide. 

 

Quick syntax examples

Types and declarations

 
int A=0;           // standard integer type, 32bits
ulong B=34;        // non-negative integer, 32bits
double X=0.5;      // double floating type, 64 bits 
float F=3.14f;     // single floating type, 16 bits, 
decimal D=0.0001m;  // financial floating type, 128 bits
string S="Hello!"; // string type
char C="#";        // char type, 8 bits
byte B=255;        // byte type, 8 bits 
uint16 W=65535;    // word integer type, 16 bits
 

Arrays

 
// Declare a single-dimensional array 
int[] array1 = new int[5];
 
// Declare and set array element values
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
 
// Alternative syntax
int[] array3 = { 1, 2, 3, 4, 5, 6 };
 
// Declare a two dimensional array
int[,] multiDimensionalArray1 = new int[2, 3];
 
// Declare and set array element values
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };
 
// Declare a jagged array
int[][] jaggedArray = new int[6][];
 
// Set the values of the first array in the jagged array structure
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };

 

// Declare the resizable list that may contain any item types 

   ArrayList StretchyList=new ArrayList();

 

// Declare the resizable list that contain double numbers. Always add the 'internal' keyword for List<> declaration in the Header  

  internal List<double> DoubleList=new List<double>()

 

IF statement

 
string Result;
// Single line IF
if (2>1) Result="2 is greater 1";
 
// Multiline IF
if (2>1)
    {
    Result="2 is greater than 1";
    Result="2 is really greater than 1";    
    }
 
// IF .. ELSE 
if (2>1)
    Result="2 is greater than 1";    
    else
    Result="Oops! 2 is less than 1";
 
// Nested IF
if (2>1)
    {
    Result="2 is greater than 1";    
    }
    else
    if (2==1)  // Notice C# equality sign ==
        {
        Result="2 is equal 1";
        }
        else 
        {
        Result="Oops! 2 is less than 1";
        }
 

Loops

 
// STANDARD LOOP
for (int i=0;i<10;i++)
   {
   ... // 10 steps
   }
 
// ADJUSTED LOOP FOR FACTORIAL
int Factorial=1;
for (int i=2;i<=10;i++)
   {
   Factorial=Factorial*i; // Factorial=1*2*3*4*5*6*7*8*9*10 
   }
 
// WHILE LOOP
int i=0;
while (i<10)
    {
    i++; // 10 steps
    }
 
// DO WHILE loop
int l=0;
do
    {
    l++; // 10 steps
    } 
while (l<11)
 

 

 

Useful links:

 

Sincerely, OkazoLab team