473,699 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odpowiednik javovego 'instance of'

Witam, jak wyglad w C# odpowiednik javovego "instance of"?

I nie odslyjacie mnieprosze do GetType() poniewaz jak mam cos takiego:

Object o = objects[i];
if(o.GetType() == Type.GetType("T u jakis typ");

to nie dziala, a mi chodiz o to ze mam ArrayList w ktrej trzymam
obiekty roznego typu i w pewnym miejscu kod wyjmuje z arraylisty po
kazdym obiekcie i sprawdzam jakiego jest typu. W javie robilbym
instance of a w C# nie wiem. Bitte pomocy, bo google "get type" ect
daje wszystko tylko nie to copotrzebuje

Dec 27 '05 #1
3 2174
<sk****@kn.pl > wrote:
Witam, jak wyglad w C# odpowiednik javovego "instance of"?

I nie odslyjacie mnieprosze do GetType() poniewaz jak mam cos takiego:

Object o = objects[i];
if(o.GetType() == Type.GetType("T u jakis typ");

to nie dziala, a mi chodiz o to ze mam ArrayList w ktrej trzymam
obiekty roznego typu i w pewnym miejscu kod wyjmuje z arraylisty po
kazdym obiekcie i sprawdzam jakiego jest typu. W javie robilbym
instance of a w C# nie wiem. Bitte pomocy, bo google "get type" ect
daje wszystko tylko nie to copotrzebuje


I don't know Polish (which I assume is the language you're writing in,
given your email address). However, I suspect you're after the "is" and
"as" operators:

if (o is SomeType)
{
...
}

And:

SomeType x = o as SomeType;
if (x != null)
{
...
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 27 '05 #2
thx! and sorery, my bad, message was supossed to go to polish usenet:)

Dec 27 '05 #3
This is extreme of trying to help someone Jon.
You are a compulsive helper and day saver :) :)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<sk****@kn.pl > wrote:
Witam, jak wyglad w C# odpowiednik javovego "instance of"?

I nie odslyjacie mnieprosze do GetType() poniewaz jak mam cos takiego:

Object o = objects[i];
if(o.GetType() == Type.GetType("T u jakis typ");

to nie dziala, a mi chodiz o to ze mam ArrayList w ktrej trzymam
obiekty roznego typu i w pewnym miejscu kod wyjmuje z arraylisty po
kazdym obiekcie i sprawdzam jakiego jest typu. W javie robilbym
instance of a w C# nie wiem. Bitte pomocy, bo google "get type" ect
daje wszystko tylko nie to copotrzebuje


I don't know Polish (which I assume is the language you're writing in,
given your email address). However, I suspect you're after the "is" and
"as" operators:

if (o is SomeType)
{
...
}

And:

SomeType x = o as SomeType;
if (x != null)
{
...
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2367
by: Robert Ferrell | last post by:
I have a question about assigning __call__ to an instance to make that instance callable. I know there has been quite a bit of discussion about this, and I've read all I can find, but I'm still confused. I'd like to have a factory class that takes a string argument and returns the appropriate factory method based on that string. I'd like the instances to be callable. Like this: fact = Factory('SomeThing') aSomeThing = fact(some...
14
3325
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this instance!
6
7743
by: Andre Meyer | last post by:
Hi all I have been searching everywhere for this, but have not found a solution, yet. What I need is to create an object that is an instance of a class (NOT a class instance!) of which I only know the name as a string. This what I tried: class A:
3
2521
by: David MacQuigg | last post by:
I am writing a chapter for teaching OOP in Python. This chapter is intended as a brief introduction to replace the more complete discussion in Learning Python, 2nd ed, pp. 295-390. I need to explain instance variables. What I'm looking for is the best compromise between brevity and a full explanation. The students are non-CIS technical professionals ( engineers and scientists ). At the point they need this explanation, they have...
4
3906
by: | last post by:
Hi I have a list containing several instance address, for example: I'd like to invoke a method on each of these instance but I don't know : 1. if its possible 2. how to proceed
18
6948
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call...
2
5561
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This brings the whole instance down and it has to be restarted. In addition the job seems to be stuck in the TOOLSDB as if I try to delete the backup job I get "The task is currently running". So I went to the command line and tried "db2 backup database...
6
8914
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? I am running UDB 8.2 on Linux and AIX. Thanks.
12
3109
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is only ever ONE instantiation of this class, and this outside method in a separate thread has to access it. How do i do this?
0
8694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8621
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9041
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8928
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7757
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2355
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.