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
assume i have 'text;.

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


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

Recommended Answers

All 5 Replies

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

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.


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

Means you have to stick with constructors.

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

No one said you can't overload operators. I said you can't overload those operators.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.