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.
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.
After learning about state machines, I want to place it in every class of my code. That's a great pleasure for me to declaratively (or "fluently") construct a machine, handle events and be sure that any logic violation will throw an exception.
Can you please critisize me on this practice? Or, may be, you install Stateless package habitually for each project (like I do)?
Any examples of state machines overusing?
Whilst design-patterns are very good practice, you should be cutting code to solve a particular problem that potentially will use a design-pattern to solve that problem in a tried-and-tested manner.
We do not write code from a "let's use this design-pattern" perspective because a single design-pattern is not a one-size fits all solution!
Do not write all your code around the state machine idiom. It will make many simple tasks over-complicated and difficult to maintain.
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 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.
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.
I get that mistake.. I use a loop to run through a bunch of images to be drawn..I also use multithreading..
What could cause that problem and how could it be prevented?
I use winforms
Additional information:
it tells me if i use graphics after GetHDv method, call the ReleaseHDC method..
What does it mean?
section of the code:
A thread created like this:
Before I did this:
BackgroundWorker1.RunWorkerAsync();
Now I am testing with this:
Backgroundworker back=new backgroundworker();
back.runworkerAsync();
is that the root of the exception?
According to this page
What's really happening with "Object is currently in use elsewhere" is
that GDI+ is complaining that the device context (DC) that it is
trying to use is already "in use". With WinForms, this generally
means there is a recursive Graphics.GetHdc occurring. GetHdc must
match a ReleaseHdc before any other GetHdc.
And
You can encounter this exception if you're drawing to a form from
multiple threads. You'll likely also be encountering a
cross-threading exception as well. The solution in this case is to
not use multiple threads when accessing a form, including drawing.