What are the differences in implementing interfaces implicitly and explicitly in C#?
When should you use implicit and when should you use explicit?
Are there any pros and/or cons to one or the other?
...
Today I happens to find that one C# class can inherit one interface both in implicit and explicit way. This surprises me. If C# works in this way, then one instance can behave differently when referenced in different way.
interface IFoo
{
void DoSomething();
}
class Foo : IFoo
{
#region IFoo Members
public void DoSomething(...
Is it possible to define an implicit conversion of enums in c#?
something that could achieve this?
public enum MyEnum
{
one = 1, two = 2
}
MyEnum number = MyEnum.one;
long i = number;
Edit:
If not, why not!! :)
...
When browsing ASP.NET MVC source code in codeplex, I found it is common to have a class explicitly implementing interface. The explicitly implemented method/property then invoke another "protected virtual" method/property with same name.
For example,
public class MvcHandler : IHttpHandler, IRequiresSessionState
{
protected virtua...
Having recently introduced an overload of a method the application started to fail.
Finally tracking it down, the new method is being called where I did not expect it to be.
We had
setValue( const std::wstring& name, const std::wstring& value );
std::wstring avalue( func() );
setValue( L"string", avalue );
std::wstring bvalue( func2()...
If I have the code:
int f(int a) { return a; }
double f(double g) { return g; }
int main()
{
int which = f(1.0f);
}
Which overload of f is called, and why?
...
Session transcript:
>type lookma.c
int main() {
printf("%s", "no stdio.h");
}
>cl lookma.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
lookma.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. ...
It seems to me its very easy to implement an implicit operator versus a TypeConverter, so I'm assuming they aren't equivalent because of the prevalence of TypeConverters in the framework (see anything that extends FrameworkElement).
But why? Wouldn't it have been much easier to create string->object and object->string implicit operator...
What are general guidelines on when user-defined implicit conversion could, should, or should not be defined?
I mean things like, for example, "an implicit conversion should never lose information", "an implicit conversion should never throw exceptions", or "an implicit conversion should never instantiate new objects". I am pretty sure ...
I'm using Scala implicits to define a rich wrapper for a Java interface:
class RichThing { def richStuff: Unit = {} }
In the companion object I define the implicit conversion and an apply factory method:
object RichThing {
implicit def rich( thing: JavaThing ) = new RichThing()
def apply() = new RichThing()
}
With this, I...
Had a coworker ask me this, and in my brain befuddled state I didn't have an answer:
Why is it that you can do:
string ham = "ham " + 4;
But not:
string ham = 4;
If there's an implicit cast/operation for string conversion when you are concatenating, why not the same when assigning it as a string? (Without doing some operator overl...
I want to be able to implicitly convert Tuples of numbers (Ints and double) into a vector object.
Assuming a Vector class with a + method
case class Vector(x: Double, y:Double){
def + (v:Vector)= new Vector(x+v.x,y+v.y)
}
My goal is to have the following code work.
val vec = (1,2)+(.5,.3) // vec == Vector(1.5,2.3)
I can get it...
I have ReSharper 4.5 and have found it invaluable so far but I have a concern; It seems to want to make every variable declaration implicit(var). As a relatively new developer how much should I trust ReSharper when it comes to this? Take the below code snippet from a method that Paints Tab Headers.
TabPage currentTab = tabCaseNotes.Ta...
I need some help. I am creating a SelectItem class like this:
public class SelectItem<T> where T : class
{
public bool IsChecked { get; set; }
public T Item { get; set; }
}
I would like the following code to be valid
SelectItem<String> obj = new SelectItem<String> { Item = "Value" };
obj.IsChecked = true;
String objValue = ...
Let's say I have an interface IMyInterface<T> that simply describes one function:
public interface IMyInterface<T>
{
T MyFunction(T item);
}
I could just about replace this with Func<T, T>, but I want the interface for semantic reasons. Can I define an implicit conversion between that interface and Func<T,T> such that I could pas...
I am somewhat new to Ruby and although I find it to be a very intuitive language I am having some difficulty understanding how implicit return values behave.
I am working on a small program to grep Tomcat logs and generate pipe-delimited CSV files from the pertinent data. Here is a simplified example that I'm using to generate the line...
Is the following free function implicitly inlined in C++, similar to how member functions are implicitly inlined if defined in the class definition?
void func() { ... }
Do template functions behave the same way?
...
Hi
I'm new to C# and learning new words. I find it difficult to understand what's the meaning of these two words when it comes to programming c#.
I looked in the dictionary for the meaning and here's what I got:
Implicit
"Something that is implicit is expressed in an indirect way."
"If a quality or element is implicit in som...
Hello,
There is a question. How JS will bevave if we compare if (true == "true") and (0 == "0") ? Is there any other tricky convertions?
...
hi folks,
i'm wondering why linkers can not do their job simply by consulting the information in the actual .dll files that got the actual implementation code ? i mean why linkers still need .lib files to do implicit linking ?
are not the export and relative address tables enough for such linking ?
is there anyway by which one can do i...