这个编程难题的灵感来源于昨天在这里提出的另一个问题,但作者删除了这个问题。
使用Visual.EXE(或您最喜欢的C# IDE)创建一个可执行二进制文件(Windows或Linux二进制),它将以下文本打印到标准输出:
Main() is the main method of C# programs!..。不使用出现在任何源文件中的连续4个字母appearing!
备注:
remainder (例如),它包含连续的4个字母M- any,但是如果它包含mxain,则4个字母将不再是连续的,因此mxain将被允许。static void M\u0061in(),因为这个答案已经被其他用户读过了,它将不再被接受!这个网站的名称是“编程难题和代码高尔夫”--这是一个“编程难题”,而不是“代码高尔夫”:挑战是在所有其他用户之前找到一个可行的解决方案,而不是找到一个比所有其他解决方案都短的解决方案。
因此,描述工作解决方案的第一篇文章就赢了!
祝好运!
顺便说一句:我有一个在下工作的解决方案。
发布于 2016-10-21 01:36:02
在Visual 2015中打开C#互动窗口(查看>其他窗口> C#互动)。我想不是所有的IDE都会有这个。
这种方法在Interactive中执行C#,以便创建一个C# exe,它无需作者编写main就可以打印所需的字符串。作为一种奖励,exe的IL也不包含main。
在“互动”窗口中运行以下代码
using System.Reflection;
using System.Reflection.Emit;
var appMeow = (dynamic)System.Type.GetType("System.AppDom" + "ain").GetProperty("CurrentDom" + "ain", BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Public).GetValue(null);
var asmName = new AssemblyName("MEOW");
var asmBuilder = appMeow.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
var module = asmBuilder.DefineDynamicModule("MEOW", "MEOW.exe");
var typeBuilder = module.DefineType("Meow", TypeAttributes.Public);
var entryPoint = typeBuilder.DefineMethod("EntryPoint", MethodAttributes.Static | MethodAttributes.Public);
var il = entryPoint.GetILGenerator();
il.Emit(OpCodes.Ldstr, "Meow() is the meow method of C# programs!");
il.Emit(OpCodes.Ldstr, "eow");
il.Emit(OpCodes.Ldstr, "ain");
il.EmitCall(OpCodes.Call, typeof(string).GetMethod("Replace", new[] { typeof(string), typeof(string) }), null);
il.EmitCall(OpCodes.Call, typeof(Console).GetMethod("Write", new[] { typeof(string) }), null);
il.Emit(OpCodes.Ret);
var type = typeBuilder.CreateType();
asmBuilder.SetEntryPoint(type.GetMethods()[0]);
asmBuilder.Save("MEOW.exe");使用Environmnent.CurrentDirectory查看创建exe的位置。运行它以观察所需的输出。

由此产生的IL:

发布于 2016-10-20 23:32:58

Main的所有实例替换为Meow
MainWindow.xaml重命名为MeowWindow.xaml。这将自动将MainWindow.xaml.cs重命名为MeowWindow.xaml.cs。
Console Application,以便创建控制台。
MeowWindow构造函数中为所需的输出字符串添加控制台写入
main。

对于WPF应用程序,Visual生成包含obj\Debug\App.g.cs方法的Main。生成的Main创建一个WPF应用程序的实例并启动它。
发布于 2016-10-19 20:12:25
我必须打破规则因为我用vim和csc.
class C {
static void \u004d\u0061\u0069\u006e(){
Syste\u006d.Co\u006esole.Write("\u004d\u0061\u0069\u006e() is the \u006d\u0061\u0069\u006e \u006dethod of C# progra\u006ds!");
}
}https://codegolf.stackexchange.com/questions/96772
复制相似问题