相关疑难解决方法(0)

c#setter中的堆栈溢出异常

这很容易解释:这很有效

using System;
using ConstraintSet = System.Collections.Generic.Dictionary<System.String, double>;

namespace ConsoleApplication2
{
    class test
    {
        public ConstraintSet a { get; set; }
        public test()
        {
            a = new ConstraintSet();
        }
        static void Main(string[] args)
        {
            test abc = new test();
            Console.WriteLine("done");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这不

using System;
using ConstraintSet = System.Collections.Generic.Dictionary<System.String, double>;

namespace ConsoleApplication2
{
    class test
    {
        public ConstraintSet a { get { return a; } set { a = value; } }
        public test()
        {
            a = new ConstraintSet(); …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow setter callstack

14
推荐指数
3
解决办法
8133
查看次数

由于StackOverFlowException C#,进程终止

这是我的代码.我无法弄清楚为什么这段代码给出了'由于StackOverFlowException而导致进程终止'.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SadiSDAL4
{
    class Program
    {
        static void Main(string[] args)
        {
            PrivateVehical privateV = new PrivateVehical("001");
            PrivateVehical pVehical = (PrivateVehical)privateV.Clone();
            Console.WriteLine("Cloned : {0}", privateV.name);
            Console.WriteLine("Cloned : {0}", pVehical.name);
            privateV.name = "Sadia's Car";
            Console.WriteLine("Cloned : {0}", privateV.name);
            Console.WriteLine("Cloned : {0}", pVehical.name);
            pVehical.name = "Waheed's Car";
            Console.WriteLine("Cloned : {0}", privateV.name);
            Console.WriteLine("Cloned : {0}", pVehical.name);
            Console.WriteLine(privateV.GetHashCode().ToString());
            Console.WriteLine(pVehical.GetHashCode().ToString());
            PublicVehical publicV = new PublicVehical("002");
            Console.WriteLine(publicV.id);
            PublicVehical pubVehi = (PublicVehical)publicV.Clone();
            Console.WriteLine("Cloned : {0}", pubVehi.id);
        } …
Run Code Online (Sandbox Code Playgroud)

c# exception

9
推荐指数
2
解决办法
3万
查看次数

发生了'System.StackOverflowException'类型的未处理异常

为什么这个?这是我的代码:

public class KPage
{
    public KPage()
    {
       this.Titolo = "example";
    }

    public string Titolo
    {
        get { return Titolo; }
        set { Titolo = value; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我通过构造函数设置数据.所以,我想做些喜欢的事情

KPage page = new KPage();
Response.Write(page.Titolo);
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误:

set { Titolo = value; }
Run Code Online (Sandbox Code Playgroud)

.net c# stack-overflow getter-setter

8
推荐指数
1
解决办法
6万
查看次数

C#set/get中的堆栈溢出错误

星期五,当我收到堆栈溢出错误时,我正在处理应用程序的公共注释部分,这让我很困惑,所以我想我会请求帮助.使用"堆栈溢出"这个表达式搜索网页有点弄巧成拙!

我想在发送要添加到数据库的类的实例之前,在类的字段的set语句中执行HtmlEncode:

public class Feedback
{

    public Feedback() { }

    public string FeedbackComment
    {
        get { return FeedbackComment; }
        set {System.Web.HttpUtility.HtmlEncode(value); }
    }

    // other fields 

    // methods
}
Run Code Online (Sandbox Code Playgroud)

这导致了StackOverflow错误,我通过将代码更改为如下所示来修复错误:

public class Feedback
{

    public Feedback() { }

    private string feedbackComment;

    public string FeedbackComment
    {
        get { return feedbackComment; }
        set { feedbackComment = System.Web.HttpUtility.HtmlEncode(value); }
    }

    // other fields 

    // methods
} 
Run Code Online (Sandbox Code Playgroud)

但我只想解释为什么第一个get/set语句是如此递归以至于它们导致堆栈溢出但是当将代码恢复为更像c#2.0时?这可以通过更短的语法来实现,如果是这样的话怎么样?

这是我的第一个问题 - 请尽量保持温和!

c# asp.net exception

5
推荐指数
2
解决办法
5924
查看次数

getter/setter中的无限循环c#

class Program
{
    static void Main(string[] args)
    {
        something s = new something();
        s.DoIt(10);
        Console.Write(s.testCount);
    }
}

class something
{
    public int testCount
    {
        get { return testCount; }
        set { testCount = value + 13; }
    }

    public void DoIt(int val)
    {
        testCount = val;
    }
}
Run Code Online (Sandbox Code Playgroud)

是我拥有的,因为我想测试和玩C#的getter/setter东西.但是,我得到一个StackOverFlowException未处理"set {testCount = value + 13}".我无法单步执行它,因为我得到一个"调试器无法继续运行进程.进程已终止"来自Visual Studio的消息.我有什么想法我做错了吗?

编辑:今天我了解到我做了一个非常愚蠢的derp.鉴于大量的即时反应.现在我知道的更好.

c#

5
推荐指数
2
解决办法
3365
查看次数

C#中的StackoverFlowException

我正在编写一个代码,用于在C#中设置属性并获得异常.

public class person
{
    public string name
    {
        set
        {
            name = value;
        }
        get
        {
            return name;
        }
    }

    public static void Main()
    {

        person p = new person();
        p.name = "Bilal";

        Console.WriteLine(p.name);
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

-1
推荐指数
2
解决办法
178
查看次数