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
  1. Home
  2. General Programming
  3. C#
  4. append(a,b,&result)

append(a,b,&result)

Scheduled Pinned Locked Moved C#
help
6 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdul Rhman Alsri
    wrote on last edited by
    #1

    string result = ""; append("Ali","Salim",&result); public void append(string a, string b, string result) { result = a +" "+ b; } Error: Error 11 Argument '4': cannot convert from 'string*' to 'string' D:\app\pup\Code\TBrectangular.aspx.cs 23 262 D:\app\

    D L A P 4 Replies Last reply
    0
    • A Abdul Rhman Alsri

      string result = ""; append("Ali","Salim",&result); public void append(string a, string b, string result) { result = a +" "+ b; } Error: Error 11 Argument '4': cannot convert from 'string*' to 'string' D:\app\pup\Code\TBrectangular.aspx.cs 23 262 D:\app\

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      It's telling you that result and &result are not the same thing. However, your public void append(string a, string b, string result) wouldn't do much anyway, since you can't modify function parameters without explicitly specifying.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      1 Reply Last reply
      0
      • A Abdul Rhman Alsri

        string result = ""; append("Ali","Salim",&result); public void append(string a, string b, string result) { result = a +" "+ b; } Error: Error 11 Argument '4': cannot convert from 'string*' to 'string' D:\app\pup\Code\TBrectangular.aspx.cs 23 262 D:\app\

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        this is the C# forum, your code does not compile here. :|

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        1 Reply Last reply
        0
        • A Abdul Rhman Alsri

          string result = ""; append("Ali","Salim",&result); public void append(string a, string b, string result) { result = a +" "+ b; } Error: Error 11 Argument '4': cannot convert from 'string*' to 'string' D:\app\pup\Code\TBrectangular.aspx.cs 23 262 D:\app\

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          While in c++ that would work just fine, C# doesn't let you manage pointers or references directly without declaring a block of code unsafe (it might be worth it for you to look up the unsafe keyword and how to use it) What C# does give you for just this type of thing is another couple of keywords for your parameters, ref and out. Both will allow you to pass the reference to your string so that you can modify it inside the function, but there is one main difference. Using the out keyword you can pass in an uninitialised variable that you expect the function to fill in. The ref keyword will only allow you to pass in variables that have been initialised as it expects the function to use and modify it. So, for this type of thing you can simply use the out keyword;

          string result;
          append("Ali", "Salim", result);

          public void append(string a, string b, out string result)
          {
          result = a +" "+ b;
          }

          Now, on a slightly different topic, if you plan on combining a lot of strings you may simply want to use the StringBuilder class, as it is a lot more efficient than simply adding two or more strings together.

          My current favourite word is: Smooth!

          -SK Genius

          1 Reply Last reply
          0
          • A Abdul Rhman Alsri

            string result = ""; append("Ali","Salim",&result); public void append(string a, string b, string result) { result = a +" "+ b; } Error: Error 11 Argument '4': cannot convert from 'string*' to 'string' D:\app\pup\Code\TBrectangular.aspx.cs 23 262 D:\app\

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Or why not simply return the string like a normal person?

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              Or why not simply return the string like a normal person?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Now you surprise me. :laugh: :laugh:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

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