hi all,
what does the following mean ?
class A
{
public string @return;
}
also, once an object is casted to class "A" how do i recast it to a "string"
?
object o = invoke(.......) ;
A a = (A)o;
string s = (string)a; /// doesn't work .
thanks, 3 1335
Maersa <ma*****@hotmai l.com> wrote: what does the following mean ?
class A { public string @return; }
That's showing that it's got a member variable called "return" - the @
is to distinguish it from the return keyword. It's a really bad idea to
use keywords as variable names though.
also, once an object is casted to class "A" how do i recast it to a "string" ?
You can't cast objects just anywhere - they have to either have an
explicit or implicit conversion, or the object has to be an instance of
the class you're casting to.
object o = invoke(.......) ; A a = (A)o; string s = (string)a; /// doesn't work .
No, it wouldn't. What do you want to get out of it though? There are
any number of strings which *could* represent that instance of A. You
could override ToString in A, and call that, or write a new method
which returns an appropriate string, depending on what you want to do,
exactly.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
On Wed, 19 May 2004 20:45:43 +0800, Maersa <ma*****@hotmai l.com> wrote: hi all,
what does the following mean ?
class A { public string @return; }
It means that the A has a public string called @return. My guess is the @ is added because 'return' is a keyword and can't be used as variable name.
also, once an object is casted to class "A" how do i recast it to a "string" ?
object o = invoke(.......) ; A a = (A)o;
For this to work, o must be some version of A in disguise
string s = (string)a; /// doesn't work .
No because a isn't a string. You can however add a method to class A
public override string ToString()
{
return "Hello World!";
}
Which will work when A is used for string building.
A a = new A();
MessageBox.Show ("" + a);
object o = "Hello World!";
string s = (string)o; // this works, because o is actually a string
object o = new A();
A a = (A)o; // this works, because as above o is actually A.
You can test if a cast will work with
if(o is string);
{
string s = (string)o;
}
else if(o is A)
{
A a = (A)o;
}
--
Happy coding!
Morten Wennevik [C# MVP]
I should probably add the all this has to do with inheritance and casting. All objects know what they were originally created to be, even though they appear to be something else later on. The objects can be casted to itself or anything it inherits from, as well as interfaces it implements.
All objects (as far as I know) is ultimately derived from the object class, so you can cast everything to object (make it pretend to be of the object class) but you have to obey strict casting rules to cast the object to something else.
Happy coding!
Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: Jukka K. Korpela |
last post by:
I have noticed that the meaning of visibility: collapse has been discussed
on different forums, but with no consensus on what it really means.
Besides, implementations differ.
The specification says:
"The 'visibility' property takes the value 'collapse' for row, row group,
column, and column group elements. This value causes the entire row or
column to be removed from the display, and the space normally taken up by
the row or column to...
|
by: Michael Kalina |
last post by:
Because when I asked for comments on my site-design (Remember? My site,
your opinion!) some of you told me never to change anything on
font-sizes!
What do you guys think of that: http://www.clagnut.com/blog/348/
I hope that's going to be a good discussion!
Michael
|
by: lester |
last post by:
a pre-beginner's question:
what is the pros and cons of .net, compared to ++
I am wondering what can I get if I continue to learn C# after I have learned
C --> C++ --> C# ??
I think there must be many know the answer here.
thanks
|
by: Steve Richter |
last post by:
What does the "." mean in the following sql script stmts?
use
GO
if exists (select * from dbo.sysobjects where
id = object_id(N'.')
and OBJECTPROPERTY(id,N'IsUserTable') = 1)
drop table .
GO
| |
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode support IDEs are DreamWeaver 8 and
Zend PHP Studio.
DreamWeaver provides full support for Unicode. However, DreamWeaver is
a web editor rather than a PHP IDE. It only supports basic IntelliSense
(or code completion) and doesn't have anything...
|
by: jacob navia |
last post by:
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are. I came up with the following text.
Please can you comment?
Did I miss something?
Is there something wrong in there?
--------------------------------------------------------------------
Types
A type is a definition for a sequence of storage bits. It gives the
meaning of the data stored in memory. If we say that the object a is an
|
by: Frank Rizzo |
last post by:
Some of the classes in the framework are marked as thread-safe in the
documentation. In particular the docs say the following:
"Any public static (*Shared* in Visual Basic) members of this type are
thread safe. Any instance members are not guaranteed to be thread safe."
What exactly does this mean? Does this mean that if I call a shared
method from 2 different threads, nothing whacky will happen?
Also when it says that instance members...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: JoeC |
last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;
What does this mean?
I have seen v=&var->member.thing;
but what does it mean when you change the & for int?
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |