为什么Foo()成功但Bar()抛出一个BadImageFormatException?
using System.Runtime.InteropServices;
using System.Text;
static class Program
{
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int sprintf([Out] StringBuilder buf, string format, __arglist);
static void Main(string[] args)
{
Foo<int>(2); //Runs fine
Bar<int>(2); //Error: "The signature is incorrect"
}
static void Foo<T>(int a) { sprintf(new StringBuilder(8), "%d", __arglist(a)); }
static void Bar<T>(T a) { sprintf(new StringBuilder(8), "%d", __arglist(a)); }
}