|
|
Well - you should use POP3 for the incoming.
|
|
|
|
|
I have some questions on type casting and inherited classes. First two easy questions:
1. What is the difference between "type casting" and "boxing"? The latter is a term that's new to me and I get the impression that it might be different terms for the same concept? Am I wrong?
2. Given ClassB cb = new ClassB();
Is there a difference between:
ClassA ca = cb as ClassA;
and
ClassA ca = (ClassA)cb;
But now for the more important question. Let's say I have two classes, ClassA and ClassB which inherits ClassA . Typecasting from ClassB to ClassA is a rather straightforward affair:
ClassB cb = new ClassB();<br />
ClassA ca = (ClassA)cb;
Is there a way to typecast the other way round? In other words, I have an instance of ClassA and I want to use it and view it as if it is of ClassB . Of course there might be some member variables specific to ClassB which might not be initialised. I would imagine that the best would be if the typecast first calls the default constructor of ClassB so that those member variables are initialised and then changes the type from ClassA to ClassB or something like that.
Am I making sense at least? Thanks in advance.
|
|
|
|
|
Dewald wrote: Given ClassB cb = new ClassB();
Is there a difference between:
ClassA ca = cb as ClassA;
and
ClassA ca = (ClassA)cb;
The difference here is that the first statement (ClassA ca = cb as ClassA; ) will perform a cast using the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.isinst.aspx">isinst</a>[<a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.isinst.aspx" target="_blank" title="New Window">^</a>] IL instruction. What this does for you is that it performs a "safe" cast in that if cb implements ClassA or is a derived class of ClassA it is cast to that type; otherwise it will return null . Also, if cb were null already, then a null is also returned.
The ClassA ca = (ClassA)cb; statement performs a cast using the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.castclass.aspx">castclass</a>[<a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.castclass.aspx" target="_blank" title="New Window">^</a>] IL instruction. If cb implements ClassA or is a derived class of ClassA it is cast to that type; otherwise it will return an InvalidCastException . Also, if cb were null already, then a new object is returned set to a null reference is also returned.
Dewald wrote: Is there a way to typecast the other way round? In other words, I have an instance of ClassA and I want to use it and view it as if it is of ClassB.
Given your examples I don't believe this is possible. If ClassA were to derive from ClassB , you could "downcast" to your base class or "upcast" to a more derived class, but those will only work in certain circumstances and you may not always get the expected results. It sounds like what you are looking for is the concept of covariance and contravariance[^], which currently do not exist in C# in a form that would allow you to do this.
Dewald wrote: What is the difference between "type casting" and "boxing"? The latter is a term that's new to me and I get the impression that it might be different terms for the same concept? Am I wrong?
Boxing is Microsoft's term for encapsulating a value type inside a reference type (usually System.Object). Boxing an instance of a value type is performed in C# by typecasting it to a reference type. An instance of the reference type is created (on the stack), containing a copy of the original value. That implies a stack allocation, plus the garbage collector needs to keep track of the new reference type. Unboxing a value is performed by typecasting the value back to the original type, thereby retrieving the actual value from within the reference.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Answer 1 : Boxing is changing Value type to Reference Type. Generally all the premitive type data is Value type. Type Casting is on the other hand is changing the datatype.
Answer 2: well you can store an object from derived class to the base class type reference. Casting is needed when you need the reverse.
In case of assigning baseclass object to derived classes.. there might be a problem, as you will find some function from derived classes from intellesense menu but are not available to the actual object as .NET brings intellesense menu from the datatype. In the reverse case you can call the derived class functions which are not listed through intellesense.
Does it look clear.
Abhishek Sur
|
|
|
|
|
I have this problem when a form is going to show this form...
frm.ShowDialog(); //here ocured the error
help pls.
spaps
|
|
|
|
|
Without knowing what this form is doing, there's not a lot to go on. Take a look at the full stack trace to try and figure out exactly what's screwed up.
|
|
|
|
|
the form getting some data from db, but all the things in the constructor is going well no prob, only when it goes to the ShowDialog(). it get me this error..
in the CALL STACK is this:
......Main() Line 225 + 0x1a bytes
in the output:
A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
spaps
|
|
|
|
|
Did you check in frm (the form you want to show) Load event or in its Constructor?
|
|
|
|
|
I've been tasked with writing a windows application. On the asp.net side we can use repeaters to create user controls but I haven't found the equivalent for windows forms. I'm trying to create a group of comboboxes from an array of items. Do I need to make collection of them? And how do I position them on the form? All I see is the absolute X Y coordinates, but what if you have 10 or 20 of these items?
Thanks
|
|
|
|
|
u will have to draw them dynamically through frm.controls.add(controlname)
if you want exactly similar to web, use WPF instead of ordinary Windows applications.
Abhishek Sur
|
|
|
|
|
What is difference between "SelectedValue" and "SelectedItem.Value" property in DropDownList component? If answer for this question is this properties are same, why microsoft wrote same two property?
Best Regards...
|
|
|
|
|
hi
the SelectedValue property is used in DataBounding, e. g.
listbox.DataSource = myArryList;
listbox.DisplayMember = "Name"; // Name is the Name of the Property/Column
listbox.ValueMember = "Text"; // Text is the Name of the Property/Column
regards
|
|
|
|
|
i want to develop a small apps which will click on the button of a particular application. how can i communicate with that specific application.is there any idea. if so then please tell me the concept and how to code this type of apps.
Thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: i want to develop a small apps which will click on the button of a particular application
do you want to click on button to your application or other application ?or you just open the other application by clicking the button ?
Tridip Bhattacharjee wrote: how can i communicate with that specific application.is there any idea.
That based on the other application which you are use. if thats also your application you can easily write some interface code .
or if that is some other application you need some API to access.
|
|
|
|
|
no i just want to click on button of other application which developed by anyone. so if u know then plzzzz share the idea with me.
thanks
tbhattacharjee
|
|
|
|
|
If the both application are written in such a way so that it have a common interface, you can use that to communicate...
For example.
Say there is a base Interface which helps in communication.
That interface should be implemented to both the application. Now you can communicate using that common interface.
Abhishek Sur
|
|
|
|
|
Hello,
I am creating the custom web crawler in c#.
I want to incorporate movie capturing of the WebPage in the application.
Where can I find the example of screen capture of WebPages in c#.
Also my exact requirement is that I want to record the full webpage or portion of the webpage for a time specified and then save it as avi.
Thanks,
Bhavin
bhavin.chheda@vizualize.com
a
|
|
|
|
|
Hi all,
How to write a dda communication program?
Regards,
Sangetha
|
|
|
|
|
Why two posts???
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Sorry..Some problem while sending the Question
|
|
|
|
|
Yeah, and it's on your side of the keyboard.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Does this [^] help?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
How to write a dda communication program?
Regards,
Sangetha
|
|
|
|
|
San wrote: How to write a dda communication program?
You research DDA (whatever that is...i have no idea), open up your favourite IDE, start coding, add features as necessary, and finally you release your shiny new application.
|
|
|
|