Click here to Skip to main content
16,006,819 members
Home / Discussions / C#
   

C#

 
GeneralRe: Access .mdb files Pin
Rob Graham22-Dec-02 10:03
Rob Graham22-Dec-02 10:03 
GeneralRe: Access .mdb files Pin
Omega50122-Dec-02 18:35
Omega50122-Dec-02 18:35 
GeneralRe: Access .mdb files Pin
Rob Graham22-Dec-02 19:20
Rob Graham22-Dec-02 19:20 
GeneralRe: Access .mdb files Pin
Omega50123-Dec-02 9:44
Omega50123-Dec-02 9:44 
GeneralRe: Access .mdb files Pin
spacemonkey22-Dec-02 11:19
spacemonkey22-Dec-02 11:19 
GeneralRe: Access .mdb files Pin
Rob Graham22-Dec-02 12:05
Rob Graham22-Dec-02 12:05 
GeneralDNS resolve Pin
Anonymous11222-Dec-02 9:43
sussAnonymous11222-Dec-02 9:43 
GeneralC# operator overloading is very limited Pin
Orantho22-Dec-02 5:49
Orantho22-Dec-02 5:49 
I want to make a class which automatically truncates text to a specified length. This is how I would like to use it while coding.

Text text = new Text(4);
text = "This text will be truncated to 4 characters.";
string truncated = text;

Truncated now should return a value of "This". Remember, this is a simplified example of what I want to do. I want to have a lot more properties and functionality than length.

Returning the value isn't a problem. I can write a conversion operator: public static implicit operator string(Text text).

But, after looking further into operator overloading I came to the conclusion that it is impossible to perform the truncation. I can never have access to the length, because operator overloading uses static functions.

I can think of several solutions to this problem but the code to use it is uncomfortable.
1. Using a new Text(...) each time. Too many properties and too much chance for errors. I really don't want to look up each time which values I need this time.
2. Since I was going to use Properties to access the Text class I could reapply all values in the set function. I could get the desired syntax but this leads to some really awful code. Plus, each time I would instantiate a new object I need to update the reference in two places.
3. Using a property in the text class: text.Data = "This ...". I guess this is the best solution although I really hate the syntax.

Can anybody come up with a good solution?

GeneralRe: C# operator overloading is very limited Pin
leppie22-Dec-02 9:42
leppie22-Dec-02 9:42 
GeneralRe: C# operator overloading is very limited Pin
Orantho22-Dec-02 10:41
Orantho22-Dec-02 10:41 
GeneralRe: C# operator overloading is very limited Pin
Joshua Nussbaum22-Dec-02 13:41
Joshua Nussbaum22-Dec-02 13:41 
GeneralRe: C# operator overloading is very limited Pin
Orantho22-Dec-02 22:06
Orantho22-Dec-02 22:06 
GeneralInternet Connections Pin
Dave Kerr22-Dec-02 5:19
Dave Kerr22-Dec-02 5:19 
GeneralDelegate/Event question Pin
Rocky Moore21-Dec-02 22:49
Rocky Moore21-Dec-02 22:49 
GeneralRe: Delegate/Event question Pin
leppie22-Dec-02 1:31
leppie22-Dec-02 1:31 
GeneralLaunch Console Applications in the background Pin
Shock The Dark Mage21-Dec-02 18:59
Shock The Dark Mage21-Dec-02 18:59 
GeneralRe: Launch Console Applications in the background Pin
leppie21-Dec-02 23:10
leppie21-Dec-02 23:10 
GeneralRe: Launch Console Applications in the background Pin
Shock The Dark Mage22-Dec-02 4:19
Shock The Dark Mage22-Dec-02 4:19 
GeneralRe: Launch Console Applications in the background Pin
Arun Bhalla26-Dec-02 13:14
Arun Bhalla26-Dec-02 13:14 
GeneralFind String in a Large String Pin
Steve McLenithan21-Dec-02 16:24
Steve McLenithan21-Dec-02 16:24 
GeneralRe: Find String in a Large String Pin
Rob Graham21-Dec-02 16:51
Rob Graham21-Dec-02 16:51 
GeneralRe: Find String in a Large String Pin
Thong Nguyen21-Dec-02 22:29
Thong Nguyen21-Dec-02 22:29 
GeneralMDB to Text Pin
Jassim Rahma21-Dec-02 9:46
Jassim Rahma21-Dec-02 9:46 
GeneralRe: MDB to Text Pin
David Stone21-Dec-02 10:19
sitebuilderDavid Stone21-Dec-02 10:19 
GeneralRe: MDB to Text Pin
jassim21-Dec-02 10:26
jassim21-Dec-02 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.