I am working on learning C# in depth. I am mostly confused by the frequent implementation of interfaces. I always read that this class implements this interface. For instance, SqlConnection class implements IDbConnection. What is the benefit for developers in this case?
66950
I understand that they force you to implement methods and such but what I cant understand is why you would want to use them. Can anybody give me a good example or explanation on why I would want to implement this.
19900
I have just found a static nested interface in our code-base.  class Foo {     public static interface Bar {         /* snip */     }     /* snip */ }   I have never seen this before. The original developer is out of reach. Therefore I have to ask SO:  What are the semantics behind a static interface? What would change, if I remove the static? Why would anyone do this?
85756
Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces popup here and there, but I haven't ever really been exposed to good explanations of interfaces or when to use them.  I am talking about interfaces in a context of interfaces vs. abstract classes.
96860
I've being reading around reasons to use or not Guid and int.  int is smaller, faster, easy to remember, keeps a chronological sequence. And as for Guid, the only advantage I found is that it is unique. In which case a Guid would be better than and int and why?  From what I've seen, int has no flaws except by the number limit, which in many cases are irrelevant.  Why exactly was Guid created? I actually think it has a purpose other than serving as primary key of a simple table. (Any example of a real application using Guid for something?)  ( Guid = UniqueIdentifier ) type on SQL Server
6832
How does one go about and try to find all subclasses of a given class (or all implementors of a given interface) in Java? As of now, I have a method to do this, but I find it quite inefficient (to say the least). The method is:    Get a list of all class names that exist on the class path Load each class and test to see if it is a subclass or implementor of the desired class or interface   In Eclipse, there is a nice feature called the Type Hierarchy that manages to show this quite efficiently. How does one go about and do it programmatically?
28147
What is reflection, and why is it useful?  I'm particularly interested in Java, but I assume the principles are the same in any language.
13131
I was reading  when I came across  saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object-Oriented Programming Languages).  So, what is the difference?
34739
Say I have an interface like this:  public interface ISomeInterface { ... }   I also have a couple of classes implementing this interface;  public class SomeClass : ISomeInterface { ... }   Now I have a WPF ListBox listing items of ISomeInterface, using a custom DataTemplate.  The databinding engine will apparently not (that I have been able to figure out) allow me to bind to interface properties - it sees that the object is a SomeClass object, and data only shows up if SomeClass should happen to have the bound property available as a non-interface property.   How can I tell the DataTemplate to act as if every object is an ISomeInterface, and not a SomeClass etc.?  Thanks!
71403
When would I implement IDispose on a class as opposed to a destructor?  I read , but I'm still missing the point.    My assumption is that if I implement IDispose on an object, I can explicitly 'destruct' it as opposed to waiting for the garbage collector to do it.  Is this correct?  Does that mean I should always explicitly call Dispose on an object?  What are some common examples of this?
105044
This might be a old question: Why does IEnumerable&lt;T&gt; inherit from IEnumerable?  This is how .NET do, but it brings a little trouble. Every time I write a class implements IEumerable&lt;T&gt;, I have to write two GetEnumerator() functions, one for IEnumerable&lt;T&gt; and the other for IEnumerable.  And, IList&lt;T&gt; doesn't inherit from IList.   I don't know why IEnumerable&lt;T&gt; is designed in other way.
99846
I need to determine if a Class object representing an interface extends another interface, ie:   package a.b.c.d;     public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{     }   according to  Class.getSuperClass() will return null for an Interface.       If this Class represents either the   Object class, an interface, a   primitive type, or void, then null is   returned.   Therefore the following won't work.  Class interface = Class.ForName("a.b.c.d.IMyInterface") Class extendedInterface = interface.getSuperClass(); if(extendedInterface.getName().equals("a.b.d.c.ISomeOtherInterface")){     //do whatever here }   any ideas?
98970
I'm not sure if this is a strange thing to do or not, or if it is some how code smell...but I was wondering if there was a way (some sort of oop pattern would be nice) to "cast" a base type to a form of its derived type. I know this makes little sense as the derived type will have additional functionality that the parent doesn't offer which is in its self not fundamentally sound. But is there some way to do this? Here is a code example to so I can better explain what I"m asking.  public class SomeBaseClass {     public string GetBaseClassName {get;set;}     public bool BooleanEvaluator {get;set;} }  public class SomeDerivedClass : SomeBaseClass {     public void Insert(SqlConnection connection) {           //...random connection stuff           cmd.Parameters["IsItTrue"].Value = this.BooleanEvalutar;           //...     } }  public static void Main(object[] args) {     SomeBaseClass baseClass = new SomeBaseClass();     SomeDerivedClass derClass = (SomeDerivedClass)baseClass;      derClass.Insert(new sqlConnection()); }   I know this seems goofy but is there any way to accomplish something of this sort?
78162
I collect a few corner cases and  and would always like to hear more. The page only really covers C# language bits and bobs, but I also find core .NET things interesting too. For example, here's one which isn't on the page, but which I find incredible:  string x = new string(new char[0]); string y = new string(new char[0]); Console.WriteLine(object.ReferenceEquals(x, y));   I'd expect that to print False - after all, "new" (with a reference type) always creates a new object, doesn't it? The specs for both C# and the CLI indicate that it should.  Well, not in this particular case. It prints True, and has done on every version of the framework I've tested it with. (I haven't tried it on Mono, admittedly...)  Just to be clear, this is only an example of the kind of thing I'm looking for - I wasn't particularly looking for discussion/explanation of this oddity. (It's not the same as normal string interning; in particular, string interning doesn't normally happen when a constructor is called.) I was really asking for similar odd behaviour.  Any other gems lurking out there?
72761
I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am I right? Is there a better way to decide when to use the interface or the concrete type?
119284
Suppose you have an interface defined in C#.  What is the easiest method to find all classes that provide an implementation of the interface?  The brute force method would be to use "Find References" in Visual Studio and manually look through the results to separate out the usages from the implementations, but for an interface in a large codebase that is heavily referenced with relatively few implementations, this can be time consuming and error prone.  In Java, running javadoc on the codebase (using the -private option to include private classes) would generate a documentation page for the interface (e.g. ) that includes all implementing classes for the interface as well as any subinterfaces (though it doesn't include implementing classes of the subinterfaces, these are relatively easy to determine by drilling down into the listed subinterfaces).  It's this functionality that I'm looking for but with C# and Visual Studio.
59558
I am looking at some code and it has this statement:    ~ConnectionManager() {     Dispose(false); }   The class implements the IDisposable interface, but I do not know if that is part of that the tilde(~) is used for.
24065
I mostly use Java and generics are relatively new. I keep reading that Java made the wrong decision or that .NET has better implementations etc. etc.  So, what are the main differences between C++, C#, Java in generics? Pros/cons of each?