本文介绍了为什么这种方法不增加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能我昨晚要喝很多酒。为什么每次在getTurns中收到值1时,此方法不会将数字的值增加1?





 class转
{
private int number;

public void Counts(int getTurn,out int getBack)
{
if(getTurn.Equals(1))
{
number ++;
}

getBack = number;

}
}
解决方案





可能,你不需要打电话给你班级的另一个实例,但你不知道如何访问现有的实例...

[]



我建议你阅读 []和 []。

使用代理或/和接口,你可以增加计数你想要的次数,只使用你班级的一个实例。



糟糕的做法总是不好的做法,无论结果如何(工作申请) !




May be I had to much drinks last night. Why this method does not increment the value of "number" by 1 every time I receive the value "1" in "getTurns"?


class Turns
    {
        private int number;

        public void Counts(int getTurn, out int getBack)
        {
            if (getTurn.Equals(1))
            {
                number++;
            }

            getBack = number;

        }
    }
解决方案



Probably, you don''t need to call another instance of your class, but you don''t know how to access to existing one...
3.7 Scopes (C#)[^]

I would suggest you to read about delegates[^] and interfaces[^].
Using delegates or/and interfaces you''ll be able to increase Counts value as many times as you wish, using only the one instance of your class.

Bad practice is always bad practice, no matter of result (working application)!




这篇关于为什么这种方法不增加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:55