User FAQs

If you have a question, please send it to us.

1) What is an Interface ?
An interface is a contract that defines the signature for any object that is derived from it.
An interface can contain methods, properties, indexers and events.
An interface cannot contain constants, fields, instance constructors, types or static members.
Interfaces can be 'public', 'private', 'internal'.
The default access modifer for an interface is 'internal'.

internal interface IMyInterface 
   void MyMethod(string MyText);
   string Property_Name { get; set; }

2) What type of Access Modifiers can you have on Interface members ?
None. You cannot use any explicit access modifiers.
Interface members are always 'public' by definition.

3) Can an Interface contain implementation ?
No. An interface can only contain the signature, it cannot contain any implementation.

4) Can an Interface implement from another Interface ?
Yes. An interface can inherit from one or more interfaces.
An interface cannot inherit from a Structure or Class.

interface IMyInterface : IBaseInterface1, IBaseInterface2 
{ }

5) Can you describe the IEnumerable interface ?
This interface enables you to use the foreach loop and for loop statements.
All the standard collection classes and the generic collection classes all implement this interface.

System.Collections.Generic.List<string> MyList; 
MyList = new System.Collections.Generic.List<string> { "one", "two", "three", "four" };
foreach (string mytext in MyList)

6) What methods does the IEnumerable interface have ?
GetEnumerator -
This interface requires that you also implement the IEnumerator interface.

7) Can you describe the IEnumerator interface ?
This interface supports a very simple iteration.

8) What methods and properties does the IEnumerator interface have ?
M - MoveNext - advanced to the next element
M - Reset - moves to the initial position which is before the first element.
M - Dispose
P - Current - returns the object at the current location

9) Which of these interfaces inherit from the IDisposable interface ?
IEnumerator - (Added in C# 1.0) doesn't inherit
IEnumerator<T> - (Added in C# 2.0) does inherit
IEnumerable<T> - (Added in C# 2.0) does inherit

10) Write your own collection that implements the IEnumerable interface

class MyCustomArray : IEnumerable, IEnumerator 
   object[] m_Items = null;
   int m_index = 0;

   public MyCustomArray()
      m_Items = new object[50];
   public void Add (object item)
       m_Items[m_index] = item;
       m_index ++;
   public IEnumerator GetEnumerator()
       foreach (object obj in m_Items)
            if (obj == null) { break; }
            yield return obj;
   public bool MoveNext()
   public void Reset()
   public object Current { get{} }

11) Can you describe and give an example of using the yield keyword ?

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext