HiCalc use C# 4.0 as programming language. We have finished the basic C# code such as handling input variables, output variables and so on,
and you need only write your calculation code in Program Code tab for your program.
Note: all output variables must be assigned value in your program.
See a live
video sample.
The Features Of C# 4.0
1. A simple, modern, general-purpose object-oriented
langauge
2. Software robustness and programmer productivity
3. Strong type checking, array bounds checking, detection of use of
uninitialized variables, source code portability, automatic garbage
collection
4. Ease of learning by programmers familiar with C++ and
Java
C# Syntax
1. Case-sensitive
2. Whitespace has no meaning
3. Sequences of space, tab, linefeed,
carriage return
4. Semicolons are used to
terminate statements (;)
5. Curly braces {} enclose
code blocks
Variables
C# is a type-safe language. Variables are declared as being of a particular type, and each variable is constrained to hold only values of its declared type.
Variables must be initialized or assigned to before
first use.
The variable name can contain letters, digits and the first character of the name must be a letter. The variable name is case-sensitive.
The C# variables types include Boolean,Integral, Floating Point, String, Char, Array...
Examples:
int number_of_slugs = 0;
string name;
float myfloat = 0.5f;
bool hotOrNot = true;
If-Else-Statements
Basically, "if" a statement is true, the code inside the if-statement runs or “else” the code inside elsestatement
will run.
Example 1:
button_state = Button.Read();
if (button_state == true)
{
LED.Write(false);
}
else
{
LED.Write(true);
}
Switch Statement
The switchstatement
will compare a variable to a list of constants (only constants) and make an
appropriate jump accordingly.
Example 1:
DateTime currentTime = DateTime.Now;
int day = (int)currentTime.DayOfWeek;
switch (day)
{
case 0:
Debug.Print("Sunday");
break;
case 1:
Debug.Print("Monday");
break;
case 2:
Debug.Print("Tuesday");
break;
default:
Debug.Print("We should never see this");
break;
}
For-Loop
In the for-loop, we need to give it three
arguments (initial, rule, action). In the very first loop, we asked it to set variable "i" to zero.
Then the loop will keep running as long as the variable "i" is less then 10. Finally, the for-loop
will increment variable i in every loop.
Example 1:
for (int i = 0; i < 10; i++)
{
//do something
}
While-loop
The while-loop start and end with curly brackets to
contain some code. Everything inside will continuously run while a statement is true
Example 1:
int MyVar=3;
while(MyVar>0)
{
MyVar=MyVar-1;
Debug.Print("Amazing!");
}
Foreach loops
The foreach statement repeats a group of embedded statements for each element in an array or an object collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects.
Example
int[] fibarray = new int[] { 0, 1, 2, 3, 5, 8, 13 };
foreach (int i in fibarray)
{
Console.WriteLine(i);
}
Comments
To comment a line, or part of a line, add // before the comment text.
You can also comment a whole block. Start the comment with /* and then end it with */
symbols.
Example 1:
// This is a comment
Example 2:
/* This is a comment
it it still a comment
the block will end now */