|
Because users of StringItem would have to cast to a string . They already know they have a StringItem instance, so why should they have to cast the return value of GetContents to string again?
In my code, the user would first have to cast from GeneralItem to StringItem anyway. So he/she actually ends up casting twice.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I think you have to live with that...
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
I want to know why there are no covariant return types, I do understand that I've to live with it, (atleast until the next version of C# rolls out, whenever that is.)
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Becouse if you use that func and think you got the parent, but got the child and it return a string when you wanted an object.
PS. They could do it with only child's to the return type is able to be a return type (and for object, that's everything...)
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
It shouldn't be a problem, after all, a string "is-a" object, so the code that calls GetContents() on GeneralItem should be able to handle any type whose base class is object.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Probably because Microsoft thought it would be confusing. Why would you want to do this ? If the overridden classes differ by return type, how will you know what you're getting back anyhow ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm anyway going to get a string if I call GetContents, whether it is on GeneralItem (with runtime type = StringItem) or StringItem directly. For StringItem, I already know I'll get a string, so why do I have to cast again? For example
private void ProcessItem(GeneralItem item)
{
Console.WriteLine(item.GetContents());
}
private void ProcessItem(StringItem item)
{
string s = (string)item.GetContents();
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You are thinking only in terms of string is a typeof object kind of way what, if the return types did not come from the same hierarchy at all eg. base class returns point your override returns string, this is a very difficult thing to keep track of especially if you want the compiler to throw errors in these kind of situations ...
|
|
|
|
|
The compiler doesn't allow that. If the overridding method's return type is different, it must be a derived class of the base class method's return type. So your case, (base class method returning Point, derived class method returning string) will not compile.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Thanks. Yes, I did read that but it doesn't seem to answer why covariant return types are not available in C#.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Hello, does anyone know how to create a texture bar in AxMSChart?
I defined a TextureBrush, but I cann't change the brush of the bar going to use the TextureBrush.
After that I am going to turn it back to normal solidbrush.
Please help.
Thanks!;)
|
|
|
|
|
I'm trying to make a custom control that shows a collection of images (and more but I'm not having a problem with the other code), there's two problems I'm coming across:
Resizing: When the control is on the form it will redraw properly when being resized smaller than it was originally drawn as, but resizing any larger will stop it redrawing properly. I've added code on the Resize event properly, and I can see it works when I resize the control smaller. I think this might be a .net problem since I've seen this before, just can't remember where...
The more critical problem: Array Property. My control has an array of "Tiles" as a property, these Tile class currently holds two properties "Name" and "Thumbnail". The control arranges and draws these thumbnails on the control. When I put the control on a form and add Tiles via the properties window of the control in the form designer, it will add the tiles fine and draw them to the control. However when I run the program or close the form designer these tiles disappear I have a feeling I need some code to maintain the data but what? It's all rather confusing
|
|
|
|
|
Don't know about the redraw issue, but as for saving properties, put this attribute in front of them: [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemComponentModel.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp
a couple of msdn pages on the subject...
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
Ok just took a look at those pages and they've completely gone over my head. Are there any simplified references on that? Like an explanation of why I need a Component class, where to have it, and how to use it in relation to a custom control....
|
|
|
|
|
i want to create a form with a per pixel image trasparent (PNG), you could think at an image with gradual shadow.
How can i use this as image for a noborder form?
Thanks for help in advance
|
|
|
|
|
Hi I'm reading data from a file with a double stored in it. What I want to do is cast the double from a string to a double. The thing is that string looks like this "37.05" instead of this "37,05".
Now what I want to know is if it is ok to just exchange the . for a , or would this cause a FormatException on some other system?
|
|
|
|
|
|
The best way is to provide a IFormatProvider from the culture in which your App is running this makes sure you have international support.
Eg,
Double.Parse(N, Thread.CurrentCulture.NumberFormat);
A short term fix is to pass a number style argument to Double.Parse, with the current decimal seperator in your case "," in some other countries ".", look up MSDN for details on numberstyles, basic format is
[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]
|
|
|
|
|
Thank you I will try that.
|
|
|
|
|
Can anyone offer any suggestions on how to make a GroupBox, or alternatively Radio Buttons within a GroupBox, ReadOnly, similar to the ReadOnly mode in Text Boxes. I dont want to use the Enable property has this makes it difficult to view. I want to have a form with several controls where the user can edit the content of controls depending on his privileges. If the user doesn't have the required privileges, I do not disable the controls but set them to ReadOnly. This way, the user can still very well read the texts in the TextBoxes, because their text is still painted in black.
den25597
|
|
|
|
|
How about creating a derived class with a readonly property, and when it's true, you ignore all mouse clicks ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you vant to do it read only in the chech_canage event handler, set it's default value, eg.: if you want it to readonly and checked than in the handler :
if(!checked) checked=true;
I know it's disgusting, but somtimes disgusting thinks is the best way. Like Assembly it's disgusting and powerful
|
|
|
|