473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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("Tu 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 2160
<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("Tu 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.com>
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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<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("Tu 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.com>
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
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...
14
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...
6
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...
3
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...
4
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
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...
2
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...
6
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? ...
12
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...

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.