|
You can use one of the following methods to do that:
if (pettable.GetType() == typeof(myType))
{
...
}
if (pettable.GetType().Name == "myType")
{
...
}
if (pettable is myType)
{
...
}
But you probably shouldn't do it that way.
When you are looking for a certain method to call, you should always do so by using an interface. Avoid looking for a concrete type in your code wherever possible. This is bad coding style!
It is a far better solution to create another interface for each method you want to know about, exactly like you did it with the pet() method. This is one of the main purposes of the syntactical construct interface: They mark a type to have a certain member (i.e. method/property/event).
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thanks Thomas,
I'm new to interfaces so thats probably why i've left that way out just now (not too confident with them !).
Regarding the first option you gave, i understand how that works, but still cant see how it will allow me to access the methods in the animals own class....say Cat class ?
Can i cast the 'pettable' to instance of an object 'Cat' ?
|
|
|
|
|
nlowdon wrote: Can i cast the 'pettable' to instance of an object 'Cat' ?
Exactly.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Instead of that, have an interface that declares the Move(), and have your animals implement the IPetAnimalKeeper, but if your animal can move, also make them implement the interface IMovingPet
if (pettable is IMovingPet)
{
((IMovingPet)pettable).Move();
}
There are other ways, probably more elegant.
|
|
|
|
|
my programme needs something in a website. But to work it correctly, website should be loaded fully. so i thought that if i obtain the value of status bar "ready" or any number represents same thing, i can achieve the aim. So is there any function in .net that returns the value of status bar. thank you
|
|
|
|
|
You would have to search the windows of internet explorer through WinAPI. Enum all of the windows and check the text of the statusbar (the statusbar is a window that gets enum-ed) for the value that it should be.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
thanks for your answer but this seems a little bit hard for me without any code.
|
|
|
|
|
You will definitely have to research this more, I do not have any code handy. I am only guiding you in the right direction for your own research.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
If you use the WebBrowser component in the ToolBox, it'll fire a DocumentCompleted event that tells you when the page is done loading.
|
|
|
|
|
thank you senior i will try webbrowser component
|
|
|
|
|
that's right. it is working but in fact i need status bar variables on the classical internet explorer pages. because i am using virtual keyboard strokes and it is using some more components on explorer page. is there any dll to use internet explorer features. for example to add a new website to my favourite list.
|
|
|
|
|
kralece wrote: it is working but in fact i need status bar variables on the classical internet explorer pages.
You can't get them. They're not exposed by anything.
kralece wrote: is there any dll to use internet explorer features. for example to add a new website to my favourite list.
Yes and no. You don't get to control the full functionality of IE. For exmaple, there is no API call to create a Favorites entry. That's nothing but a shortcut created in the users Favorites folder with a URL in it instead of a file path. Other stuff is exposed by the WinInet[^] API functions.
|
|
|
|
|
thank you sir for your enlightening informations
|
|
|
|
|
Is there any tool to create a simple line diagram or other diagrams? If so, how can I get it/them?
I can't find any in the toolbox for Microsoft Visual C# 2008 Express Edition, Windows Forms Application.
|
|
|
|
|
|
That's great!
But I can't get the ZedGraphControl in the toolbox. I have added the zedgraph.dll just as it was written in the example you gave me, but I can't find it.
In the "Download C# Sample Project" I can see the control in the form and see the resulting graf if I run the program. But even their the ZedGraphControl is not in the toolbox.
Maybe it's because I use version 2008?
|
|
|
|
|
Yes i can do that
Follow next steps.
1.Rigth Click in general tool box, select option "choose items"
2.select tab .net frameworl componet
3. And the trick ... Click in Browse dll
4.Find and select dll ZedGraph.dll and drag and drop in general tool box
5.is done , now you can see zedgraph control and ready for you use
|
|
|
|
|
I have an application that uses a datagridview to display all the values in a particular datatable, while individual field values for the currently selected are shown in text boxes, comboboxes, etc. below the grid.
Anyway, when I call GetChanges() on the bound datatable, the datatable returned by the GetChanges() method often returns rows as modified even if all the current and original values in that row are equal. When I first load the application, this is not the case, but when I start navigating through the table, each row that I leave is marked as Modified.
Any advice regarding the cause and solution of this "error" would be appreciated.
Thanks.
|
|
|
|
|
Evning All,
Can anyone tell me if it's possible to fire an event (add components to a form) when you click on the tab of a 'TabControl'
I've learned that with other components in the form you 'double click' on say.....a button and it automatically takes you generated code that you can add to.
However, when designing the form you can't double click on an individual tab so i was wondering i there is such a feature.
Regards
Neil
|
|
|
|
|
There is probably a tab changed event or something. Another option may be to get the click event of the tab control and then figure out which tab was clicked.
|
|
|
|
|
Hi,
you want the TabIndexChanged event.
It handles the entire TabControl, not individual pages, so if you need code specific for each page you might want to insert a switch statement there.
|
|
|
|
|
Hi,
I have self signed certificate and I am running my java web service on tomcat on https. I can access the wsdl with the browser. I need C# client to access this service. I already have a C# client that uses this service via http.
So I generated the stub with wsdl c# utility. What do I do next so I can use my java web service in c# client via https.
Thanks.
|
|
|
|
|
Hi Everyone,
I am working on a C# windows application in DotNet 2005. I want to show some address form DB on Map, and plot the route also. I checked the Virtual Earth. If I am using the Virtual Earth, I have to make and HTML page and show in the Web Browser control. But by this I wont be able to communicate with it from my Windows Application.
As I am very new to this thing... Can anyone who has worked on this type of things, please tell me what is good to use in my situation Virtual Earth or MS Mappoint ?
Thanking in advance.
Priya
Priya
|
|
|
|
|
How to create a DSN programmatically in C#? I need to create a DSN for Oracle.
|
|
|
|
|
For Oracle, I use the classes in Oracle.DataAccess.Client
I start with an XML file with a list of databases:
<ORACLEHR Type="ORACLE" Server="servername" Port="8080" Username="HR" Password="hr" />
and pass the information to something like:
string.Format
(
"Data Source={0}:{1};User Id={2};Password={3};"
,
Server
,
Port
,
Username
,
UserPassword
)
to produce the connection string.
|
|
|
|