小编low*_*att的帖子

如何在c#中实现选择性属性可见性?

我们可以使类的属性对公众可见,但只能由某些特定类修改吗?

例如,

// this is the property holder
public class Child
{
    public bool IsBeaten { get; set;}
}

// this is the modifier which can set the property of Child instance
public class Father
{
    public void BeatChild(Child c)
    {
        c.IsBeaten = true;  // should be no exception
    }
}

// this is the observer which can get the property but cannot set.
public class Cat
{
    // I want this method always return false.
    public bool TryBeatChild(Child c) …
Run Code Online (Sandbox Code Playgroud)

c#

10
推荐指数
1
解决办法
197
查看次数

python不能从staticmethod调用模块方法?

考虑以下模式:

'''some module body'''

def __foo():
    '''module method foo'''
    pass

class Dummy(object):
    @staticmethod
    def bar():
        __foo()

__foo() # No Error.
Dummy.bar() #NameError: Global name "_Dummy__foo" is not defined.
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

-

如果用"__"命名它是不好的,那么Python中使模块方法仅用于内部模块函数/方法的最佳做法是什么?

python

4
推荐指数
1
解决办法
125
查看次数

如何在Python中区分具有相同元素的两个列表?

假设我们有两个列表:

a = [1, 2, 3]
b = [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

以下所有表达式都将返回True:

a == b  # True
a == list(b) # True
a == list(tuple(b)) # True
a == copy.deepcopy(b) # still True
Run Code Online (Sandbox Code Playgroud)

这里ab具有相同的元素2个不同的列表对象.我们如何区分彼此?

python

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

标签 统计

python ×2

c# ×1