|
if(myOwn is Car)<br />
{<br />
}
or
if(myOwn.GetType() == typeof(Car))<br />
{<br />
}
They are the same in essence.
|
|
|
|
|
Just to add to J4amieC 's suggestion, if you need to actually use the methods of your specific class, you could use the as keyword to reduce the number of casts that you'll use. For example:
Car c = someObject as Car;
if( c != null )
{
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
There's a small difference between using is and as .
If you use as and then check for null you don't know if someObject actually is a Bike or if it's a Car with value null .
With is you can really test for the correct type.
Usually this won't matter, but it's a different meaning nevertheless...
Regards,
mav
|
|
|
|
|
Well the idea is:
Car car = someObj as Car;
Boat boat = someObj as Boat;
Plane plane = someObj as Plane;
if (car != null) {
}
else if (boat != null) {
}
else if (plane != null) {
}
The assumption is that your testing classes on the same level in the class hierarchy.
If your not testing classes on the same level, then the difference between is and as matters. But you could also write your if-else statement so that it tests the more specific class types to the more broad class types.... lol
Anyways,
David
|
|
|
|
|
I agree with you about most of that. If I use typeof on a null value, then I still not get what I need in terms of runtime type information. Here, a use of as prevents an extra cast later on. For example, in the following code, we pass null values and with both is and as , we cannot retrieve runtime type information:
public class Foo {}
public class Goo {}
public class Test
{
[STAThread]
static void Main( string[] args )
{
Foo f = null;
Goo g = null;
Foo ff = new Foo();
Goo gg = new Goo();
Console.WriteLine( Form1.TestMeAsFoo( f ) );
Console.WriteLine( Form1.TestMeAsFoo( g ) );
Console.WriteLine( Form1.TestMeAsFoo( ff ) );
Console.WriteLine( Form1.TestMeAsFoo( gg ) );
Console.WriteLine( Form1.TestMeIsFoo( f ) );
Console.WriteLine( Form1.TestMeIsFoo( g ) );
Console.WriteLine( Form1.TestMeIsFoo( ff ) );
Console.WriteLine( Form1.TestMeIsFoo( gg ) );
}
public static bool TestMeIsFoo( object o )
{
return ( o is Foo );
}
public static bool TestMeAsFoo( object o )
{
return ( o as Foo ) != null;
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
-- modified at 15:24 Monday 5th December, 2005
|
|
|
|
|
Hello all, I am currently taking a C# programming class and have no prior knowledge of any programming. I am to write a program that takes a user's input and encrypt it, only using the ASCII code table (32-126). Now I know that there is a way of doing without re-inventing the wheel to say. I just can not find it. I think I need to use a character array, but just can not figure it out. Also I know that there is something in the System.Security that does this, but can not find out any information. Please help. Thanks
Rich Poulin
|
|
|
|
|
|
Hi,
I am making an application in VSC# 2005 which has a "WebBrowser" control in it, I want to be able to manipulate a webpage in the webrowser control from within the application.
I have worked out how to get (and set) the text in a form on the webpage with something like;
webBrowser1.Document.GetElementById("Textbox1").InnerText.ToString();
which is fine, but I just can't work out how to invoke a button on the webpage. Basically I want to get the text from the form, change it, paste it back into the form (all of which I can do) and then call the "Save" button to save my changes (which I can't do). Any help would be greatly appreciated!
Thanks in advance, Martin.
|
|
|
|
|
OK I worked out one way, by putting the user focus on the correct button, then simulating pressing the enter key;
webBrowser1.Document.GetElementById("Save").Focus();
SendKeys.Send("{ENTER}");
but it's pretty ugly, and possibly not very robust. Anyone got any better ideas?
thanks
|
|
|
|
|
how can I do to get the disk space of a computer of a domain (The domain hasn´t got Active Directory)?
thanks
|
|
|
|
|
This may not be possible unless you have an application sitting on the target machine that will publish how much disk space is free.
On the other hand, I'm no expert when it comes to Windows networking, so take this with a grain of salt.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
how can I do to get a list of all the computer of a domain (The domain hasn´t got Active Directory)?
And how can with a list the printers?
|
|
|
|
|
i am working with [b]Windows control library[/b] in c#.i am using ShDocVw.dll in my project. i add a refrence of this dll into my project. but the problem is that when i complie this project it gives me an error dll doesn't have strong name. i already have one another dll with strong name. how can i add another dll using strong name. or i s there is any anther alternative to put this dll into Globlal Assembly.
Amit Grover
CDAC R&D
Gist Group
pune
|
|
|
|
|
Hi Amit,
If you want to add shdocvw.dll to the gac go to your project and then
In the solution explorer right click on the project name in the window.In the contextual menu click properties under the common properties\general category
you will see wrapper assembly for activex\com objects in the 'wrapper assembly key file' give the name of .snk file with wchih you want to sign this assembly.you can use the same key.compile it and then register it using gacutil.Hope it Helps.
Rakesh
|
|
|
|
|
i go through the same way as u have written.i named ShDocVw to "wrapper assembly key file" . where do i use this .snk Key.i had already used "AssemblyKeyFile" attrubute in Assemblyinfo.cs file. becoz i m using one another dll also.
after giving name ShDocVw to "wrapper assembly key file" when i compile.it is giving the same error " ShDocVw.dll does have strong name. if i used second AssembleKeyFile attribute in assemblyinfo.cs it is giving an error "duplicate assembly key file attribute" . how can i solve this problem
Amit Grover
CDAC R&D
Gist Group
pune
|
|
|
|
|
Hi,
I display a lot of images in a context menu, using OwnerDraw=true and overring OnMeasureItem/OnDrawItem. The automatically displayed arrows are great, but the menu takes all the screen height! My boss want the menu to be shorter...
I tried to display only a few images, and added my own arrow items at the beginning and the end of them, but I can't make the menu scroll when I click/select the arrows!
- when clicking the arrows, the menu automatically closes
- when selecting them, I dynamically modify the images items, but I can't make the menu update!
I tried everything: Refresh/Update/Invalidate of the parent control, PerformSelect on all the images items, calling SendMessage with WM_PAINT, WM_PRINT, WM_PRINT_CLIENT with the menu handle, and the parent control handle, I've even tried to set to false then back to true all the images items OwnerDraw, they update more or less, but the false ownerdraw menu (brief) displaying is awful!
I didn't manage to find an answer to my problems on the web, so if someone have a clue it would be great to tell me! Either about how making my long menu not taking all the screen height, or forcing the menu to update when I dynamically modify it!
Thanks a lot
Thibaud
|
|
|
|
|
Allow the menu to close as normal when the arrows are selected, update the items, and make it appear in the same location again.
If you added the context menu to the control using the "ContextMenu" Property create a delegate for the MouseDown event and note the location of the mouse when the right mouse button is clicked.
Update the menu items, then call:
myCtrl.ContextMenu.Show(myCtrl, savedX, savedY);
David
|
|
|
|
|
Hi, thanks for your answer. That's a goog idea yes, I will try it. But I'm afraid the menu closing then re-opening will be unaesthetic.
Otherwise, I have found another solution on a French forum: http://www.csharpfr.com/code.aspx?ID=34929
This solution consists in using the SetMenuInfo API to set the maximum menu height. But you also need to create a new contextmenu class, as SetMenuInfo needs a handle, and the only valid handle can be obtained by calling CreateMenuhandle, which is a ContextMenu protected method!
|
|
|
|
|
Considering that I'm a novice C# user there may be a very simple answer to this problem. I have 3 tabs in my application; one where the search parameters are entered and the second where the related file is displayed in a richtextBox. For some reason unless I view the richtextbox tab before I try load a file into it I am unable to view any loaded files. Any help in this regard would be appreciated.
Kind Regards,
Alvin
|
|
|
|
|
Some code would definitely help. Where are you instantiating the textbox?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
hi, how can i save a real picture on the SQL DB and retrieve it through .net
Thanks alot
Hamody
|
|
|
|
|
I'm having a very odd problem. I have a basic C# form app that pInvokes into a C++ dll. When I build my C++ dll and C# app in Release mode, the C# app can load the dll and call into it just fine.
However if I build the solution in Debug mode, the C# app throws a DllNotFoundException. I've double checked and the C++ debug version of the dll is being properly copied into the C# app's bin/debug folder, so its actually there.
Why is it able to load the release version and not the debug version?
|
|
|
|
|
dxben wrote: I've double checked and the C++ debug version of the dll is being properly copied into the C# app's bin/debug folder, so its actually there.
And the name of the debug dll is the same?
xacc.ide-0.1 released! Download and screenshots
|
|
|
|
|
Yeah its the same. Actually someone else pointed out to me that my debug dll is probably dependent on the debug dll of the CRT and that it can't find it. So I need to make sure the debug DLL of CRT is in my path. What is the filename of the debug crt DLL?
|
|
|
|
|
i have an object
public class Class2 : System.MarshalByRefObject
{
public Class2 ( ) { } // default constructor
public Class2 (string param1, string param2) { }
}
i cant use the 2nd constructor with remoting, when i use wsdl on the remoting url it doesnt have a signature for the 2nd constructor.
how do i implement this?
thanks
|
|
|
|