小编use*_*282的帖子

如何指定一个类但不是某个子类的对象?

class A
{

}

class B : A
{

}

void method(A that is not a B argument) {}
void generic_method(generic_class<A that is not a B> generic_argument) {}
void params_method(params A that is not a B[] params_arguments) {}
Run Code Online (Sandbox Code Playgroud)

有没有任何语法方法来做到这一点?我意识到我可以做到

if(argument is B)
    throw new ArgumentException("argument cannot be a B", "argument");
Run Code Online (Sandbox Code Playgroud)

在第一个方法的开头,并在foreach中为第二个和第三个方法执行此操作,但我想知道是否有一些关键字或OOP概念可以更好地完成此操作.

c# oop

10
推荐指数
2
解决办法
144
查看次数

let语句中的case语句需要什么缩进?

在哈斯克尔工作,发现奇怪的行为,将其剥离为裸骨

这个作品

a :: Bool
a = case True of
    True -> True
    False -> False
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试

b :: IO Bool
b = do
    let b' = case True of
        True -> True
        False -> False
    return b'
Run Code Online (Sandbox Code Playgroud)

我明白了

ghci>:l test.hs
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:16:14: parse error on input ‘->’
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)

所以我试试

c :: IO Bool
c = do
    let c' = case True of
            True -> True
            False -> False …
Run Code Online (Sandbox Code Playgroud)

haskell indentation do-notation

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

Tkinter Grid Columnspan 被忽略

考虑以下python脚本

#!/usr/bin/env python
from Tkinter import Tk, Label

width = SOME_VALUE_HERE

root = Tk()
label1 = Label(root, text='1 columns wide')
label2 = Label(root, text='%i columns wide' % width)

label1.grid()
label2.grid(row=0,column=1,columnspan=width)

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

当我运行它时,无论为“SOME_VALUE_HERE”设置什么值,两个标签都占据窗口的一半,无论是否调用了 Grid.columnconfigure,或者是否在 grid() 中使用了粘性参数。

除非我忽略了一些东西,否则我会认为设置 columnspan 会强制第二个标签的宽度是第一个标签的 'SOME_VALUE_HERE' 倍。

我误解了网格的工作原理吗?我将如何实现这种行为?

grid tkinter columnspan

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

标签 统计

c# ×1

columnspan ×1

do-notation ×1

grid ×1

haskell ×1

indentation ×1

oop ×1

tkinter ×1