I recently wrote a console program. This program has a simple function, that is, exporting data from the database (specifying the table name, specifying the table field name) to the WORD file, and the program has been completed, during the test, it was found that after you export a database table, if you want to export data from another table, you have to re-run the program. This is obviously not good. However, if you use a loop or a goto statement in a program, there are too many texts in the console. So I finally thought about whether to allow the console to automatically clear the screen and export the next database table after importing a database table. Then I searched the internet for a long time and did not find a satisfactory answer. The "clear screen" method on the Internet is to output n carriage returns. I think this is not a clear screen at all. I suddenly thought of using C ++ to write a clear screen DLL, and the result was satisfactory. The following is a step-by-step implementation of the C # language in the console:
(1) Open VS2005 and create a C ++ class library project named CLS;
(2) Open the CLS. h file and rename the class name to "CLS ";
(3) Open the CLS. cpp file and introduce the "windows. h" file;
// This is the main DLL file.
# Include "stdafx. h"
# Include "windows. h"
# Include "CLS. h"
(4) add static methods in the CLS class (the access attribute is public)
Public ref class CLS
{
Public:
Static void cls ()
{
System ("cls ");
}
};
(5) Compile the entire project and introduce CLS. dll in the CLS/debug/folder into the C # project;
(6) Call CLS. cls () to clear the screen. You can also implement pause and other functions. The method is the same as above.
So why? As long as you have learned. net FrameWork should be very clear, because no matter whether it is C ++, C, VB or C # Language, it will eventually generate the IL (Intermediate Language) Language, therefore, no matter which language you use to write programs, you can use each other.