It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Hi my workmate just told me that it is possible to achieve polymorphism by hiding a base class method and implementing another method with the same signature in the derive class, Is this true and how could this be needed in real life situations?
I guess your friend was talking about shadowing. It's not true polymorphism and should be avoided Difference between shadowing and overriding in C#?
That is pretty much anti-polymorphism. The 'real' method for the object should be executed whenever called, regardless of the type of the variable, for polymorphism; you expect derived.Method() to be called whether you call it on a variable of type base or type derived, if the object in question is of type derived.
Hiding breaks that expectation.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Is it possible to encounter Runtime error while using Generics? Could anybody give an
example?
public Someclass<T>
{
int i;
}
In what situation, this implementation can encounter an runtime error? Could anybody show any implementation by which the above class can encounter a runtime error?
The implementation you showed doesn't really do anything, so it, itself, is very unlikely to exhibit any runtime errors (other than a potential OutOfMemoryException on creation if you're out of memory).
If you had other code within the class, it, of course, could exhibit different behavior, and cause other errors to occur. Using this class, as well, could exhibit errors at runtime, but that error would technically be in the code that used the class, not arising from within the class itself, as this class has no methods defining behavior.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I've read it's generally a good idea to use interfaces as return types to reduce coupling. When is it a BAD idea to use an interface as a return type
There are two general cases when you shouldn't use an interface as a return type:
When your callers need functionality of the class that is not also available through an interface, and
When your class is part of a framework that puts additional requirements on returning interfaces (e.g. classes used with WCF).
In all cases when you can use an interface as a return type it is a good idea to use one.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Sometimes I have static types which are really supposed to be static but in rare cases I need to reuse some of their code (couple of methods). I could create an interface or another basic abstract class and solve the problem for several static classes which all really require same methods and members to be overridden but slightly modified. But it still will require me to copy paste large sections of code and I will not be able mark them as static anymore.
You could solve this by building Singleton classes. They can then leverage a base abstract class as well as any necessary inheritance hierarchy, but they still could have static methods that just leverage the private instance if necessary.
Have a look at Jon Skeet's blog on Singleton's so that you build yours properly.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
The SerializableAttribute class is explained on this link. In the start it is written:
Indicates that a class can be serialized
Can anybody expalin what this means (the bold part). I am not clear about it.
Serializing an object (an instance of a class) means turning it into something that can be written on a file or broadcasted over the network, such as an XML file (Xml serialization) or a Byte array (binary serialization).
This needs to be a two way operation, so you must be able to "Deserialize" the object.
In order to be serializeble an object must contains just serializable fields/property or fields marked as not serialized. For example a Sql connection is not serialized (it would make no sense deserializing it somewhere else...)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Look at the sceene here , please:
http://social.microsoft.com/Forums/getfile/3600/
why it's not matching?
EDIT: Okay, now we know it's XmlReader.Value, which does return a string, that's definitely not the problem. I'll leave the previous answer below for future reference.
My guess is that there are some "odd" Unicode characters which don't show up in the debugger... or that the watch window is behaving strangely. Putting a watch on xml.Value.ToCharArray() would help to show that.
(As an aside, giving a Dictionary<,> parameter the name list is very confusing...)
EDIT: Additionally, using bracing and indentation would also make your code easier to follow...
We can't tell for sure at the moment, but my guess is that the Value property is of type object, not string. That means that == and != perform reference comparisons (operators are overloaded, not overridden, remember). You want the polymorphic behaviour of:
if (xml.Value.Equals("\n"))
or if xml.Value can legitimately be null:
if ("\n".Equals(xml.Value))