Some Brain-Teaser in WinDev, Can you Solve them?

从Frankred的博客上看到他post的几个出现在WinDev上的Brain-teaser,感觉很有意思,似乎有做文字游戏的味道。在WinDev上回答正确这四题中的两题,可是有机会获得ViewSonic V37 Pocket PCs大奖。事实上,奖品最后落到了两个幸运儿身上。那么请你来看看,想一想假如当时你也在WinDev现场,是否有机会获得这件奖品?

brain-teaser #1:

以一行代码替换TBD(待定)注释,使程序显示"Win-Dev"字符串结果。要求:不能修改或增删已有代码;只能是一行代码替换TBD注释行;不能使用Console类。

class App {
            static void Main() {
                // TBD
            }
        }

        sealed class Internal {
            sealed class Private {
                static void PrintMessage( string s1, string s2 ) {
                    System.Console.WriteLine(s1 + "-" + s2);
                }
            }
        }

后三题都是写出运行结果。可以自己去运行一下,不过最好在运行之前,先分析一下是否能得出正确结果。

brain-teaser #2:

class C
        { 
        const string s = @" 
        class C 
        {{
        const string s = @{1}{0}{1};
        static void Main()
        {{
        System.Console.WriteLine(s,s,'\u0022');
        }}
        }}";
        static void Main()
        {
        System.Console.WriteLine(s,s,'\u0022');
        }
        }

:怎么样,有文字游戏的味道吧:-)

brain-teaser #3:

运行在Everett(?不知道是什么,也许是VS的一个版本?)下,结果是什么?
运行在WhidBey下,结果又是什么?

using System;
        using System.Runtime.InteropServices;
        public class Program
        {
            static void Main()
            {
                SomeType s;
                unsafe
                {
                    Console.WriteLine("{0} {1} {2} {3} {4}",
                        (byte*)&s.Field1 - (byte*)&s,
                        (byte*)&s.Field2 - (byte*)&s,
                        (byte*)&s.Field3 - (byte*)&s,
                        sizeof(SomeType),
                        Marshal.SizeOf(typeof(SomeType)));
                }
            }
        }

        struct SomeType
        {
            public char Field1;
            public int Field2;
            public char Field3;
        }

brain-teaser #4:

using System;
        using System.Threading;
        class Class1
        {
            static void Main()
            {
                Console.WriteLine("A");
                new Class2();
                GC.Collect();
                new Class1();
                GC.Collect();
                Console.WriteLine("B");
            }

            ~Class1()
            {
                Console.WriteLine("C");
                Class2.Are.Set();
                Console.WriteLine("D");
            }
        }

        class Class2
        {
            public static ManualResetEvent Are = new ManualResetEvent(false);
            ~Class2()
            {
                Console.WriteLine("E");
                Class2.Are.WaitOne();
                Console.WriteLine("F");
            }
        }

我想,brain-teaser #1的答案明天公布更好些吧。当然Frankred自然是公布了答案的,否则我是解不出正确答案的:-)

posted @ 2004-10-31 20:45  张逸  阅读(1516)  评论(5编辑  收藏  举报