interface

C#: How can Dictionary<K,V> implement ICollection<KeyValuePair<K,V>> without having Add(KeyValuePair<K,V>)?

让人想犯罪 __ 提交于 2019-12-18 12:26:27
问题 Looking at System.Collections.Generic.Dictionary<TKey, TValue> , it clearly implements ICollection<KeyValuePair<TKey, TValue>> , but doesn't have the required " void Add(KeyValuePair<TKey, TValue> item) " function. This can also be seen when trying to initialize a Dictionary like this: private const Dictionary<string, int> PropertyIDs = new Dictionary<string, int>() { new KeyValuePair<string,int>("muh", 2) }; which fails with No overload for method 'Add' takes '1' arguments Why is that so?

Using the Universal Chess Interface

别等时光非礼了梦想. 提交于 2019-12-18 12:15:17
问题 I'm planning on making a program that interfaces with a UCI chess engine. I've been doing some research on it, but I want to get a little more information before I get more in depth with it. I was wondering if any of you could provide a few example "exchanges" between a UCI engine and a front-end program. I'm not really concerned with the practical interface code (like sending/receiving commands), that should be simple enough. I'm just trying to get some good examples of a small game and some

Are Interfaces Compatible With Polymorphism

Deadly 提交于 2019-12-18 12:14:07
问题 I am having trouble with the concept of interfaces interacting with polymorphic types (or even polymorphic interfaces). I'm developing in C# and would appreciate answers staying close to this definition, although i think that still gives plenty of room for everyone to put forth an answer. Just as an example, let's say you want to make a program to paint things. You define an interface for the actor that Paints, and you define an interface for the subject which is painted, Furthermore you have

Is “public static final” redundant for a constant in a Java interface?

允我心安 提交于 2019-12-18 12:07:19
问题 This code: interface Config { int MAX_CONN = 20; } compiled and worked as I expected. It looks like this is the same as: interface Config { public static final int MAX_CONN = 20; } Is "public static final" redundant for a constant in a Java interface? Is this true for Java 1.1, 1.2, 1.3, 1.4,..., 1.8 or did it change in a Java release? 回答1: Variables declared in Interface are implicitly public static final . This is what JLS 9.3 says : Every field declaration in the body of an interface is

Why I need Interface? [duplicate]

强颜欢笑 提交于 2019-12-18 11:59:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Interfaces: Why can't I seem to grasp them? Why would I want to use Interfaces? I think this question is repeated 1000 times and I'm sorry for asking again. I really looking for a plain simple answer why I explicitly need interface, or if you please explain something I can't achieve without Interface. If it is multiple inheritance then I would request you to give me one simple example through which I can

Interface Contract, Class Object?

限于喜欢 提交于 2019-12-18 11:52:43
问题 Is contract to interface as object is to class? What is the need to differentiate identical things like this, from the code to the executing code? I sort of get the idea behind naming a class a class and the instantiated executing class an object, but overall, is that the only reason for these semi-redundant terms? 回答1: Not really. There are four terms here, so I'll go over each of them: Interface An interface is an abstract class (in languages like Java where there is no multiple inheritance

Difference Between Interface and Class [duplicate]

喜欢而已 提交于 2019-12-18 11:32:03
问题 This question already has answers here : What is the difference between an interface and abstract class? (34 answers) Closed 6 years ago . As the title states i want to know the difference between using the class like this public class Account { public string Username { get; set; } public string Password { get; set; } } and using and Interface like this public class Account : IAccount { public string Username { get; set; } public string Password { get; set; } } public interface IAccount {

Convert nil interface to pointer of something in Golang?

拈花ヽ惹草 提交于 2019-12-18 11:28:08
问题 In the following code piece, trying to convert a nil interface to a pointer of something fails with the following error: interface conversion: interface is nil, not *main.Node type Nexter interface { Next() Nexter } type Node struct { next Nexter } func (n *Node) Next() Nexter {...} func main() { var p Nexter var n *Node fmt.Println(n == nil) // will print true n = p.(*Node) // will fail } Play link here: https://play.golang.org/p/2cgyfUStCI Why does this fail exactly? It's entirely possible

Defining implicit and explicit casts for C# interfaces

 ̄綄美尐妖づ 提交于 2019-12-18 11:22:33
问题 Is there a way to write interface-based code (i.e. using interfaces rather than classes as the types accepted and passed around) in C# without giving up the use of things like implicit casts? Here's some sample code - there's been a lot removed, but these are the relevant portions. public class Game { public class VariantInfo { public string Language { get; set; } public string Variant { get; set; } } } And in ScrDictionary.cs, we have... public class ScrDictionary: IScrDictionary { public

Objective C - How can I create an interface?

霸气de小男生 提交于 2019-12-18 11:13:50
问题 I need to be able to create an interface like you create in C# to enforce a group of classes to implement certain methods. Is this possible in objective c? 回答1: You can create a protocol. it would look something like this: in MyProtocol.h: @protocol MyProtocol -(void)myMethod; -(void)myMethod2; @end in MyClass.h #import "MyProtocol.h" @interface MyClass : NSObject<MyProtocol> @end If you want to receive objects of a given protocol, you can do so like this: id<MyProtocol> var; or NSObject