0

Hey,
was wandering if somebody could help we with some classes and objects, I haven't done c# in a while and i can't remember.

Could someone tell me what String falls under in c#, ie allowing one to write somthing like

static void Main(string[] args)
{
     string s = "foobar";        
     int i = s.IndexOf('f');

}

How would a write my own class that I could handle like the string class
i.e.
assume i have 'text;.

static void Main(string[] args)
{
     text s = "foobar";        
     s.myownmethod();

}

how would i write the text class so that it acts the same as
the string class? without a constructor?
Thanks
any help would be appreciated.

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by CrazyProgrammer
0

String is a reference type. Because it is used so often, the C# compiler works out all the details for you.

0

String is a class that acts like a value type in some ways. One of those is the assignment operator. The designers made it this way because it is so commonly used.

Unfortunately:

=, ., ?:, ->, new, is, sizeof, typeof These operators cannot be overloaded.

Means you have to stick with constructors.

0

Ahhhhhh,
wait i can't overload operators in C# :( ill go back to c++ bye :P
sweet
thanks guys, soz if my questions are a bit naive

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.