one. .Net Framework
1. How to get the system folder
Use the GetFolderPath method of the class; for example:
( )
2. How to get the path to the exe file being executed
1) Use the ExecutablePath property of the Application class
2) ().Location
3. How to detect the operating system version
Use the OSVersion property of Envioment, for example:
OperatingSystem os = ;
(());
(());
4. How to obtain the file name part of the file based on the complete file name,
Use the class method GetFileName or GetFileNameWithoutExtension method
5. How to obtain the file extension through the full name of the file
Using static methods
6. What are the differences between Vb and C# click here
7. How to obtain the current computer username, whether it is connected to the Internet, how many monitors, the domain, how many keys the mouse has, etc.
Use the static properties of the SystemInformation class
8. What is the function of modifying the [STAThread] characteristics of the Main method?
It indicates that the current program is run in a single thread
9. How to read the content of the csv file
Through OdbcConnection, you can create a link to a csv file. The format of the link string is: "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq="+cvs folder path +" Extensions=asc,csv,tab,txt; Persist Security Info=False";
After creating the connection, you can use DataAdapter and other to access the csv file.
See details here
10. How to obtain disk overhead information, the code snippet is as follows, mainly calling GetDiskFreeSpaceEx external method.
public sealed class DriveInfo
{
[DllImport("", EntryPoint = "GetDiskFreeSpaceExA")]
private static extern long GetDiskFreeSpaceEx(string lpDirectoryName,
out long lpFreeBytesAvailableToCaller,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes);
public static long GetInfo(string drive, out long available, out long total, out long free)
{
return GetDiskFreeSpaceEx(drive, out available, out total, out free);
}
public static DriveInfoSystem GetInfo(string drive)
{
long result, available, total, free;
result = GetDiskFreeSpaceEx(drive, out available, out total, out free);
return new DriveInfoSystem(drive, result, available, total, free);
}
}
public struct DriveInfoSystem
{
public readonly string Drive;
public readonly long Result;
public readonly long Available;
public readonly long Total;
public readonly long Free;
public DriveInfoSystem(string drive, long result, long available, long total, long free)
{
= drive;
= result;
= available;
= total;
= free;
}
}
Can be passed
DriveInfoSystem info = ("c:"); to obtain the overhead of the specified disk
11. How to get the index position of a case-insensitive substring
1) Use the IndexOf method of the string by converting two strings to lowercase:
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// The line below will return -1 when expected is 4.
int i = (strChild);
// The line below will return proper index
int j = ().IndexOf(());
2)
A more elegant way is to use the IndexOf method of the CompareInfo class below the namespace:
using ;
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// We create a object of CompareInfo class for a neutral culture or a culture insensitive object
CompareInfo Compare = ;
int i = (strParent,strChild,);
1. How to get the system folder
Use the GetFolderPath method of the class; for example:
( )
2. How to get the path to the exe file being executed
1) Use the ExecutablePath property of the Application class
2) ().Location
3. How to detect the operating system version
Use the OSVersion property of Envioment, for example:
OperatingSystem os = ;
(());
(());
4. How to obtain the file name part of the file based on the complete file name,
Use the class method GetFileName or GetFileNameWithoutExtension method
5. How to obtain the file extension through the full name of the file
Using static methods
6. What are the differences between Vb and C# click here
7. How to obtain the current computer username, whether it is connected to the Internet, how many monitors, the domain, how many keys the mouse has, etc.
Use the static properties of the SystemInformation class
8. What is the function of modifying the [STAThread] characteristics of the Main method?
It indicates that the current program is run in a single thread
9. How to read the content of the csv file
Through OdbcConnection, you can create a link to a csv file. The format of the link string is: "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq="+cvs folder path +" Extensions=asc,csv,tab,txt; Persist Security Info=False";
After creating the connection, you can use DataAdapter and other to access the csv file.
See details here
10. How to obtain disk overhead information, the code snippet is as follows, mainly calling GetDiskFreeSpaceEx external method.
public sealed class DriveInfo
{
[DllImport("", EntryPoint = "GetDiskFreeSpaceExA")]
private static extern long GetDiskFreeSpaceEx(string lpDirectoryName,
out long lpFreeBytesAvailableToCaller,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes);
public static long GetInfo(string drive, out long available, out long total, out long free)
{
return GetDiskFreeSpaceEx(drive, out available, out total, out free);
}
public static DriveInfoSystem GetInfo(string drive)
{
long result, available, total, free;
result = GetDiskFreeSpaceEx(drive, out available, out total, out free);
return new DriveInfoSystem(drive, result, available, total, free);
}
}
public struct DriveInfoSystem
{
public readonly string Drive;
public readonly long Result;
public readonly long Available;
public readonly long Total;
public readonly long Free;
public DriveInfoSystem(string drive, long result, long available, long total, long free)
{
= drive;
= result;
= available;
= total;
= free;
}
}
Can be passed
DriveInfoSystem info = ("c:"); to obtain the overhead of the specified disk
11. How to get the index position of a case-insensitive substring
1) Use the IndexOf method of the string by converting two strings to lowercase:
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// The line below will return -1 when expected is 4.
int i = (strChild);
// The line below will return proper index
int j = ().IndexOf(());
2)
A more elegant way is to use the IndexOf method of the CompareInfo class below the namespace:
using ;
string strParent = "The Codeproject site is very informative.";
string strChild = "codeproject";
// We create a object of CompareInfo class for a neutral culture or a culture insensitive object
CompareInfo Compare = ;
int i = (strParent,strChild,);
12Next pageRead the full text