473,396 Members | 2,113 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,396 software developers and data experts.

A question on string object

Hi all,

Sorry if my question looks weird. But i still want to
understand. Let's see the below code

Dim myStr as string = "Hello"
Msgbox(myStr) ' Would display hello

I am wondering about the behaviour of the string as an object.
How comes it can receive and produce values without accessing any of
its properties. In other words, How to create a class that could behave
exactly like how String behaves.

i.e., For example, if i create a class called "MyOwnString"
What should i do so that below code can work

Dim myStr as MyOwnString = "Hello" ' Should get assgined
Msgbox(myStr) ' Should
display assigned value

Thanks,
Saran.

Apr 4 '06 #1
2 885
It's a good question, and I can give you a partial answer.

First, you must understand that strings are very special in .NET. The
functionality you describe works by calling special IL instructions, in this
case ldstr (load string). All assignment operators are that have a left hand
side string variable will use ldstr. There's no real way for you to do the
exact same thing.

As shown here:
http://blog.dreamprojections.com/arc...04/05/768.aspx

you can overload the implicit operator back to the underying type to achieve
something somewhat like the same behaviour, but the underlyign
implementation is quite different.

Karl

--
http://www.openmymind.net/

"Saran" <sx*****@qwest.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi all,

Sorry if my question looks weird. But i still want to
understand. Let's see the below code

Dim myStr as string = "Hello"
Msgbox(myStr) ' Would display hello

I am wondering about the behaviour of the string as an object.
How comes it can receive and produce values without accessing any of
its properties. In other words, How to create a class that could behave
exactly like how String behaves.

i.e., For example, if i create a class called "MyOwnString"
What should i do so that below code can work

Dim myStr as MyOwnString = "Hello" ' Should get assgined
Msgbox(myStr) ' Should
display assigned value

Thanks,
Saran.

Apr 4 '06 #2
Thanks Karl

Now i got an insight about it.

-Saran

Apr 6 '06 #3

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
8
by: Grant Wagner | last post by:
I'm a bit confused by String() (typeof 'string') vs new String() (typeof 'object'). When you need to access a method or property of a -String-, what type is JavaScript expecting (or rather, what...
12
by: Joe Fallon | last post by:
I would like to know the syntax to check that an Object is a String. If it was a number test I might use IsNumeric. But there is no function: IsString (is there?) -- Joe Fallon
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
6
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
1
by: macupryk | last post by:
+ ex {"The name \"CHARACTER\" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted."}...
26
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.