c# attribute over main

后端 未结 3 1194
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 08:29

Someone asked me a question as to how we can print

line no 1
line no 2
line no 3

Without changing a main method which reads



        
3条回答
  •  青春惊慌失措
    2021-01-02 09:32

    I think Ilya Ivanov's answer is possibly the best one. However consider mine as a funny answer too:

    public class Program
    {
        static Program()
        {
            Console.WriteLine("line no 1");
            Console.WriteLine("line no 2");
            Console.WriteLine("line no 3");
            Environment.Exit(0);
        }
    
        static void Main(string[] args)
        {
            Console.WriteLine("line no 2");
        }
    }
    

提交回复
热议问题