小编gts*_*s13的帖子

C#无法将方法转换为非委托类型

我有一个叫做的课Pin.

public class Pin
{
    private string title;

    public Pin() { }

    public setTitle(string title) {
        this.title = title;
    }
    public String getTitle()
    {
        return title;
    }
}
Run Code Online (Sandbox Code Playgroud)

从另一个类我在引脚中添加Pins对象,从另一个类我List<Pin>想迭代List引脚并获取元素.所以我有这个代码.

foreach (Pin obj in ClassListPin.pins)
{
     string t = obj.getTitle;
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,我无法检索标题.为什么?

(注意:ClassListPin只是一个包含一些元素的静态类,其中一个是List<Pin>引脚)

.net c# methods delegates

32
推荐指数
5
解决办法
8万
查看次数

如何在 Kotlin 中使用 Koin 注入 ViewModel?

我们如何使用 Koin 为 ViewModel 注入依赖项?

所以例如,我有一个ViewModel这样的:

class SomeViewModel(val someDependency: SomeDependency, val anotherDependency: AnotherDependency): ViewModel()
Run Code Online (Sandbox Code Playgroud)

现在这里的官方文档指出,要提供一个ViewModel我们可以执行以下操作:

val myModule : Module = applicationContext {

    // ViewModel instance of MyViewModel
    // get() will resolve Repository instance
    viewModel { SomeViewModel(get(), get()) }

    // Single instance of SomeDependency
    single<SomeDependency> { SomeDependency() }

    // Single instance of AnotherDependency
    single<AnotherDependency> { AnotherDependency() }
}
Run Code Online (Sandbox Code Playgroud)

然后注入它,我们可以这样做:

class MyActivity : AppCompatActivity(){

    // Lazy inject SomeViewModel
    val model : SomeViewModel by viewModel()

    override fun …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-viewmodel koin

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

检查enumsets是否具有相同的枚举值

我有两个EnumSet.

EnumSet.of(A1, A2, A3);
EnumSet.of(A3, A4, A5, A6);
Run Code Online (Sandbox Code Playgroud)

我想找到两个集合中存在哪些值.(在这种情况下,A3.)

有没有快速的方法呢?

java collections enums enumset

7
推荐指数
4
解决办法
2154
查看次数