小编Bob*_*son的帖子

Lambda实现接口

在书中我正在阅读"Head First Design Patterns",Command Pattern中有一个例子,他们用Lambda代替了Interface.

这只是Java能够做到的吗?这是一个例子

从书中: 在此输入图像描述

// Receiver 
public class Light
{
    public void On() {
        Console.WriteLine("Lights on");
    }

    public void Off() {
        Console.WriteLine("Ligts off");
    }
}

// Command interface
public interface ICommand
{
    void Execute();
}

// Concrete command
public class SimpleCommandLightOn : ICommand
{
    private readonly Light light;

    public SimpleCommandLightOn(Light light) {
        this.light = light;
    }

    public void Execute() {
        light.On();
    }
}

// Concrete command
public class SimpleCommandLightOff : ICommand
{
    private readonly Light light;

    public …
Run Code Online (Sandbox Code Playgroud)

c# design-patterns

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

如何将dll文件添加到Git Repository

我正在使用 bitbucket 来托管我的 git 存储库。我添加了一个名为 ExtLibs 的新文件夹并添加了一堆 dll。但是,当我尝试签入这些文件时,它们不会出现在 SourceTree 中。

如何将包含(dll)文件的文件夹添加到 repo?

我从这里使用 .gitignore (c#/VS2013)

在此处输入图片说明

git bitbucket atlassian-sourcetree sourcetree

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

基类实现接口

  1. 基类实现接口的缺点/风险是什么?
  2. 总是在子类上实现接口更好吗?
  3. 你什么时候使用其中一个?

    public interface IFriendly
    {
        string GetFriendly();
    }
    
    
    public abstract class Person: IFriendly
    {
        public abstract string GetFriendly(); 
    }
    
    Run Code Online (Sandbox Code Playgroud)

    VS.

    public interface IFriendly
    {
        string GetFriendly();
    }
    
    public abstract class Person
    {
       // some other stuff i would like subclasses to have
    }
    
    public abstract class Employee : Person, IFriendly
    {
        public string GetFriendly()
        {
            return "friendly";
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

.net c# oop

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