【发布时间】:2010-09-19 05:39:30
【问题描述】:
特别是,是否有可能在 c# 编译时执行类似于此 c++ 代码的代码?
template <int N>
struct Factorial
{
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0>
{
enum { value = 1 };
};
// Factorial<4>::value == 24
// Factorial<0>::value == 1
void foo()
{
int x = Factorial<4>::value; // == 24
int y = Factorial<0>::value; // == 1
}
【问题讨论】:
-
某种寻找 t4 模板 抱歉在 iphone 上无法指向资源。 Scott Hansleman 上周发布了关于它的信息。
-
试试看script.net;更多信息在 --orbifold.net/default/?p=2457
-
您可以阅读 Kevin Hazzard 和 Jason Bock 在 .NET manning.com/hazzard 中的元编程
-
@Jordão:Boo 是一种非常不同的语言,自从 Jetbrains 雇佣了大脑以来,Nemerle 或多或少已经死了。也许 Script.NET 值得一提。
标签: c# metaprogramming