Skip to main content
Revised for better clarity. Pronouns ("it") with unclear references are replaced with specific words.
Source Link

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessiblethat implicit implementation allows you to access the interface through yourthe class you created when it is castby casting the interface as that class as well as when its castand as the interface itself. Explicit implementation allows ityou to access the interface only be accessible when castby casting it as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardlessRegardless, I rarely use it.

I am sure there are more reasons to use it/not use itexplicit that others will post.

See the next post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible through your class you created when it is cast as that class as well as when its cast as the interface. Explicit implementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardless I rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

See the next post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference is that implicit implementation allows you to access the interface through the class you created by casting the interface as that class and as the interface itself. Explicit implementation allows you to access the interface only by casting it as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. Regardless, I rarely use it.

I am sure there are more reasons to use/not use explicit that others will post.

See the next post in this thread for excellent reasoning behind each.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible through your class you created when it is cast as that class as well as when its cast as the interface. Explicit implementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardless I rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

See the next postnext post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible through your class you created when it is cast as that class as well as when its cast as the interface. Explicit implementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardless I rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

See the next post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible through your class you created when it is cast as that class as well as when its cast as the interface. Explicit implementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardless I rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

See the next post in this thread for excellent reasoning behind each.

ImplicitImplicit is when you define your interface via a member on your class. ExplicitExplicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyToIList.CopyTo would be implicitly implememntedimplemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicityexplicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible throuhthrough your class you created when it is cast as that class as well as when its cast as the interface. Explicit implentationimplementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when iI need two implemetationsimplementations. But regardless iI rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

EIT: See the next postnext post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implememnted as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicity as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible throuh your class you created when it is cast as that class as well as when its cast as the interface. Explicit implentation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when i need two implemetations. But regardless i rarely use it.

I am sure there are more reasons to use it/not use it that others will post

EIT: See the next post in this thread for excellent reasoning behind each.

Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implemented as:

public void CopyTo(Array array, int index) { throw new NotImplementedException(); } 

and explicitly as:

void ICollection.CopyTo(Array array, int index) { throw new NotImplementedException(); } 

The difference being that implicitly is accessible through your class you created when it is cast as that class as well as when its cast as the interface. Explicit implementation allows it to only be accessible when cast as the interface itself.

MyClass myClass = new MyClass(); // Declared as concrete class myclass.CopyTo //invalid with explicit ((IList)myClass).CopyTo //valid with explicit. 

I use explicit primarily to keep the implementation clean, or when I need two implementations. But regardless I rarely use it.

I am sure there are more reasons to use it/not use it that others will post.

See the next post in this thread for excellent reasoning behind each.

Clarifying example: explicitely show that the object is declared as concrete class and not as an interface to avoid confusion
Source Link
Loading
code formatting
Source Link
Ufuk Hacıoğulları
  • 38.6k
  • 14
  • 120
  • 157
Loading
add link to other post
Source Link
mattlant
  • 15.4k
  • 4
  • 37
  • 44
Loading
Source Link
mattlant
  • 15.4k
  • 4
  • 37
  • 44
Loading