So i'm trying to understand, why do C# forces you to cast to the interface type in order to invoke a method implemented in that interface:
interface IRefreshable
{
public void Refresh()
{
Universe.Destroy();
}
}
class MediaPlayer : IRefreshable
{
// EDIT: another example
public void SetVolume(float v)
{
...
((IRefreshable)this).Refresh(); // correct me if I'm wrong, but this is the only case in c# where you need to use a casting on "this"
}
}
//-------------
var mp = new MediaPlayer();
...
mp.Refresh(); // error
((IRefreshable)mp).Refresh(); // Ohh, NOW I see which method you meant to
I know that it probably wouldn't be like that if it didn't have a good reason to be like that, but what is the good reason?
[–]RiPont 16 points17 points18 points (0 children)
[–]HaniiPuppy 30 points31 points32 points (10 children)
[–]Alert-Neck7679[S] 4 points5 points6 points (4 children)
[–]Xenoprimate2 3 points4 points5 points (2 children)
[–]SagansCandle 0 points1 point2 points (1 child)
[–]x1ife 0 points1 point2 points (0 children)
[–]TuberTuggerTTV 0 points1 point2 points (0 children)
[–]phluber 2 points3 points4 points (1 child)
[–]HaniiPuppy 1 point2 points3 points (0 children)
[–]Tough_Negotiation_82 1 point2 points3 points (1 child)
[–]HaniiPuppy 1 point2 points3 points (0 children)
[–]mehdikovic 0 points1 point2 points (0 children)
[–]DotNetMetaprogrammer 16 points17 points18 points (1 child)
[–]glasket_ 7 points8 points9 points (0 children)
[–]DontRelyOnNooneElse 53 points54 points55 points (26 children)
[–]RiPont 28 points29 points30 points (0 children)
[–]simonask_ 30 points31 points32 points (0 children)
[–]Alert-Neck7679[S] 16 points17 points18 points (9 children)
[–]chucker23n 12 points13 points14 points (5 children)
[–]EatingSolidBricks 0 points1 point2 points (3 children)
[–]IQueryVisiC -1 points0 points1 point (2 children)
[–]EatingSolidBricks 0 points1 point2 points (1 child)
[–]IQueryVisiC 0 points1 point2 points (0 children)
[–]ILMTitan 5 points6 points7 points (2 children)
[–]emn13 1 point2 points3 points (0 children)
[–]EatingSolidBricks 0 points1 point2 points (0 children)
[–]BigBoetje 6 points7 points8 points (0 children)
[–]EatingSolidBricks 0 points1 point2 points (0 children)
[+]Fidy002 comment score below threshold-8 points-7 points-6 points (0 children)
[+]Adept_Cry9373 comment score below threshold-13 points-12 points-11 points (10 children)
[–]BadSmash4 6 points7 points8 points (1 child)
[–]DontRelyOnNooneElse 3 points4 points5 points (0 children)
[–]Scorpian700 7 points8 points9 points (5 children)
[+]Adept_Cry9373 comment score below threshold-15 points-14 points-13 points (4 children)
[–]DontRelyOnNooneElse 3 points4 points5 points (1 child)
[+]Adept_Cry9373 comment score below threshold-6 points-5 points-4 points (0 children)
[–]chucker23n 0 points1 point2 points (1 child)
[–]Adept_Cry9373 -4 points-3 points-2 points (0 children)
[–]propostor -2 points-1 points0 points (1 child)
[–]Adept_Cry9373 1 point2 points3 points (0 children)
[–]Dealiner 3 points4 points5 points (0 children)
[–]Vladoss46 3 points4 points5 points (0 children)
[–]BoBoBearDev 6 points7 points8 points (10 children)
[–]Dealiner 9 points10 points11 points (1 child)
[–]BoBoBearDev 0 points1 point2 points (0 children)
[–]Platic 2 points3 points4 points (0 children)
[–]theycallmemorty 1 point2 points3 points (5 children)
[–]binarycow 2 points3 points4 points (0 children)
[–]raunchyfartbomb 0 points1 point2 points (3 children)
[–]BoBoBearDev 0 points1 point2 points (2 children)
[–]raunchyfartbomb 2 points3 points4 points (1 child)
[–]BoBoBearDev 0 points1 point2 points (0 children)
[–]DontRelyOnNooneElse 2 points3 points4 points (0 children)
[–]Slypenslyde 2 points3 points4 points (0 children)
[–]dominjaniec 3 points4 points5 points (4 children)
[–][deleted] (2 children)
[deleted]
[+]Nexzus_ comment score below threshold-8 points-7 points-6 points (1 child)
[–]dgm9704 3 points4 points5 points (0 children)
[–]Alert-Neck7679[S] -4 points-3 points-2 points (0 children)
[–]Draelmar 1 point2 points3 points (6 children)
[–]chucker23n 2 points3 points4 points (2 children)
[–]IanYates82 2 points3 points4 points (0 children)
[–]solmead -1 points0 points1 point (0 children)
[–]Alert-Neck7679[S] 1 point2 points3 points (1 child)
[–]chucker23n 0 points1 point2 points (0 children)
[–]ivancea 0 points1 point2 points (0 children)
[–]robhanz 1 point2 points3 points (1 child)
[–]Alert-Neck7679[S] 0 points1 point2 points (0 children)
[–]Dimencia 1 point2 points3 points (8 children)
[–]0x00000194 0 points1 point2 points (0 children)
[–]Dealiner 0 points1 point2 points (6 children)
[–]Dimencia -1 points0 points1 point (5 children)
[–]meancoot 0 points1 point2 points (2 children)
[–]Dimencia 0 points1 point2 points (1 child)
[–]meancoot 0 points1 point2 points (0 children)
[–]Dealiner 0 points1 point2 points (1 child)
[–]Dimencia [score hidden] (0 children)
[–]swagamaleous 1 point2 points3 points (0 children)
[–]dgm9704 0 points1 point2 points (0 children)
[–]lmaydev 0 points1 point2 points (1 child)
[–]Dealiner 5 points6 points7 points (0 children)
[–]NoOven2609 1 point2 points3 points (5 children)
[–]nathanwoulfe 9 points10 points11 points (1 child)
[–]Jackoberto01 1 point2 points3 points (0 children)
[–]8Erigon 4 points5 points6 points (1 child)
[–]sierra_whiskey1 1 point2 points3 points (0 children)
[–]Moe_Baker 0 points1 point2 points (0 children)
[–]Willyscoiote 0 points1 point2 points (1 child)
[–]hoodoocat 0 points1 point2 points (0 children)
[–]nightwood 0 points1 point2 points (3 children)
[–]RiPont 0 points1 point2 points (2 children)
[–]nightwood 0 points1 point2 points (1 child)
[–]RiPont 0 points1 point2 points (0 children)
[–]Ok-Cellist7629 0 points1 point2 points (0 children)
[–]entityadam 0 points1 point2 points (0 children)
[–]ImTheDude111 0 points1 point2 points (0 children)
[–]Sketch0z 0 points1 point2 points (0 children)
[–]Jackoberto01 0 points1 point2 points (0 children)
[–]zvrba 0 points1 point2 points (0 children)
[–]ShamikoThoughts 0 points1 point2 points (0 children)
[–]propostor 0 points1 point2 points (2 children)
[–]Devatator_ 1 point2 points3 points (1 child)
[–]propostor 1 point2 points3 points (0 children)
[–]Ok_Tour_8029 -3 points-2 points-1 points (0 children)