Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
H

hzs

@hzs
About
Posts
5
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Operator overloading with strings
    H hzs

    I've decided to continue using my Add() method. However your point about the "abc" string; since I would be converting the string to an int in my overloaded method, I'd get an error in case "abc" were used; so to avoid this I'd check that the user only enters numeric data. that out of the way, I'd still like to know how to overload + for string or int. (just curios). thanks....hasan

    C# help question

  • Operator overloading with strings
    H hzs

    Hmm...I believe you're right about the maintinence...overloading would cause a lot of confusion so I guess I'll just use my Add & Sub functions. However you've mentioned that "although the language might allow you to do what you want, do you really want to do it?" and I'm curious how does the languge allow me to do what I want i.e how does it allow me to overload +, - operators etc. for primitive datatypes like int and sting. Hasan P.S. The part about going home at 5 went straight to my heart :-D

    C# help question

  • Operator overloading with strings
    H hzs

    Your solution Ista wrote: public static string operator + ( string s1, string s2 ) { return (Int32.Parse(s1) + Int32.Parse(s2)).ToString(); } doesn't work...I've had already tried it. The compiler generates an error: One of the parameters of a binary operator must be a containing type". So the + operator can't be overloaded in this way.

    C# help question

  • Operator overloading with strings
    H hzs

    right. But I don't want to have to convert the stings to ints every time as i'm using around 15 for each calculation and doing what you suggested would make the code sort of confusing. I think it can be done using operator overloading so that the developer can add two strings simply by writing string3=string1+string2 Anyone with some other solution?

    C# help question

  • Operator overloading with strings
    H hzs

    I need to apply arithmatic operations on string i.e. string1 = "12"; string2 = "10"; string3 = string1+ string2; and now I want string3 to contain "22" currently I'm using functions like Add(string1, string2) which is a pain. The problem is that the above statement (string3 = string1+ string2) will concatenate the two strings not add them and overloading the + operator doesn't work. The compiler gives an error saying One of the parameters of a binary operator must be a containing type. If I make my own String class, the overloading works fine. Anyone got any ideas? thanks in advance...hasan

    C# help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups