Saturday, 26 July 2008

Debug in VS

Use print like function to out put the feedback from the code, like Console.WriteLine.

But use this method, there could be too many outputs from the program. In VS, you can choose View -> Output to see the information about compilation and execution.

Instead of using Console.WriteLine, there are other two options Debug.WriteLine and Trace.WriteLine. The first option only works in debug builds and second only works in release build. And both write to the Output window. They are included in System.Diagnostics.

In VS, user also can set up break point like other IDE does.

Tuesday, 22 July 2008

Functions in C#

Most functions in C# are the same as other programming languages.

To pass array in C#, it uses params <type>[] <name>

For example,
Define: static int SumVals(parame int[] vals)
Use: SumVals(1,2,3,4,5);

Pass the parameter by reference in C#, ref is the keyword. In this case even without returning the value from the function, the variable also can be changed.

For example,
Define: static void ShowChange(ref int val)
Use: ShowChange(MyVal);

Another similar way to pass the value is using the out keyword. The difference is that,
1. It is illegal to use an unassigned variable as a ref parameter, but it is fine as an out parameter;
2. An out parameter must be treated as an unassigned value;

Main() function can contain the 'string[] args' or have no argument.

Monday, 21 July 2008

QT starting

I won't use QT if I can avoid it, because it does have some compatibility problem.

Good point is that it is free and not difficult to implement.

QT compilation and making uses,

qmake -project
qmake
make

In every GUI application there is one QApplication object, which manages various application-wide resources, such as the default font and cursor etc.

Header file <QApplication> and class name QApplication. For each class which is part of the public QT API, it has a header file with the same name, like QPushButton class has the same name header <QPushButton>.

The QApplication object must be created before any GUI-related features of Qt are used.

QApplication features:

QCoreApplication is QApplication's base class. It can be used when developing non-GUI applications.

In QCoreApplication::exec(), Qt receives and processes user and system events and passes these on to the appropriate widgets.

To change the default font,
QApplication::setFont()

Saturday, 12 July 2008

Array declare

In C#, the array is declared in the same ay as Java like,

int[] array1;
array1= new int[7];


foreach is "new" in C# to handle arrays.

string is a specific case of array. There are lots of functions developed for it, like trim to remove the whitespace etc.

Flow control in C#

The goto statement has been abandoned in lots of programming languages, but do not know why MicroSoft pick it up again in C#.

labelName:

goto labelName


It has the normal if ... else ..., switch ... case ..., do ... while ..., and for. Just like Java or C/C++, it can be broken by break.

Tuesday, 1 July 2008

C# From the beginning

In C/C++ the output uses printf. In Java it uses System.out.println. Now we are in C# and it uses Console.Writeln.

There is a keyword, region, which can be used to collapse lines of code into a single line.

Namespace has been used in C#. It has been also used in C++ and Java. By default the global namespace is applied. The keyword is namespace.

Follows are namespace examples,

namespace LevelOne
{
 // "NameOne" define
}

In global namespace, it needs to be used as LevelOne.NameOne.

For nested namespace,
namespace LevelOne
{
 namespace LevelTwo
 {
 // "NameTwo" define
 }
}

To use NameTwo in global namespace, it should be used as LevelOne.LevelTwo.NameTwo.