以下是msdn的教程._flushall的输出在教程中是"Test",但我通过使用console.write()显示输出得到"2".有人可以解释一下吗?
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}
Run Code Online (Sandbox Code Playgroud) 以下异常处理方法是否正确?我发现很难记录错误,最后通过电子邮件发送日志文件.我在哪里编写代码来记录错误并发送电子邮件?
我得到的一个主要问题是,当生成异常SomeClass1时会记录两次 - 第二次来自SomeClass2.创建一个自定义异常类型(SomeException在示例中)并System.Exception在发生时包装它是一个好主意吗?
另外,当我们有一连串的try-catches彼此调用时,我很困惑如何以及何时向最终用户显示错误消息.
class SomeClass1
{
public static DataExtract(string sourcepath)
{
try
{
OleDbConnection oledb = new OleDbConnection();
oledb.ConnectionString = "someconnectionstring";
CompanyOLEDB.Open();
}
catch (Exception e)
{
throw new CustomException(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
class SomeClass2
{
private void SomeMethod()
{
try
{
// some code
// some code
SomeClass1.DataExtract()
}
catch (Exception e)
{
throw new CustomException(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
public class CustomException : Exception
{
protected CustomException() { } …Run Code Online (Sandbox Code Playgroud) 如何在c#中使用visual fox pro(.dbf)创建表时为字段设置索引(使用oledb).我想为表创建多个索引,一些索引是表达式(field1 + field2).