Without using recursion how can a stack overflow exception be thrown?

前端 未结 10 1954
自闭症患者
自闭症患者 2021-01-18 04:19

Without using recursion how can a stack overflow exception be thrown?

10条回答
  •  生来不讨喜
    2021-01-18 04:58

    Easiest way to make a StackOverflowException is the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                SomeClass instance = new SomeClass();
                string name = instance.Name;
            }
        }
    
        public class SomeClass
        {
            public string Name
            {
                get
                {
                    return Name;
                }
            }
        }
    }
    

提交回复
热议问题