compiler error: cannot convert type void to string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    compiler error: cannot convert type void to string

    I call method Foo(string s);

    with Foo("foo"+"bar" );

    what's the deal here?
  • Jon Skeet [C# MVP]

    #2
    Re: compiler error: cannot convert type void to string

    On Oct 8, 4:20 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
    I call method Foo(string s);
    >
    with Foo("foo"+"bar" );
    >
    what's the deal here?
    My guess is that you're doing something like:

    string x = Foo("foo" + "bar");

    If not, please show a short but complete program which demonstrates
    the problem.

    Jon

    Comment

    • Ignacio Machin ( .NET/ C# MVP )

      #3
      Re: compiler error: cannot convert type void to string

      On Oct 8, 11:20 am, puzzlecracker <ironsel2...@gm ail.comwrote:
      I call method Foo(string s);
      >
      with Foo("foo"+"bar" );
      >
      what's the deal here?
      post your complete code

      I do nt know if you are doing
      string s = Foo("foo"+"bar" );
      or
      Foo( Foo("foo"+"bar" ) );

      Comment

      • Ignacio Machin ( .NET/ C# MVP )

        #4
        Re: compiler error: cannot convert type void to string

        On Oct 8, 11:20 am, puzzlecracker <ironsel2...@gm ail.comwrote:
        I call method Foo(string s);
        >
        with Foo("foo"+"bar" );
        >
        what's the deal here?
        In any case your method is returning void, it should be returning
        string

        Comment

        • puzzlecracker

          #5
          Re: compiler error: cannot convert type void to string

          On Oct 8, 11:22 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
          On Oct 8, 4:20 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
          >
          I call method Foo(string s);
          >
          with Foo("foo"+"bar" );
          >
          what's the deal here?
          >
          My guess is that you're doing something like:
          >
          string x = Foo("foo" + "bar");
          >
          If not, please show a short but complete program which demonstrates
          the problem.
          >
          Jon
          I just call a method, with concatenation of two strings,that takes
          string parameter. That's all.

          BTW what is wrong with string x = Foo("foo" + "bar"); ?

          Comment

          • Duggi

            #6
            Re: compiler error: cannot convert type void to string

            On Oct 8, 8:43 am, puzzlecracker <ironsel2...@gm ail.comwrote:
            On Oct 8, 11:22 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
            >
            >
            >
            On Oct 8, 4:20 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
            >
            I call method Foo(string s);
            >
            with Foo("foo"+"bar" );
            >
            what's the deal here?
            >
            My guess is that you're doing something like:
            >
            string x = Foo("foo" + "bar");
            >
            If not, please show a short but complete program which demonstrates
            the problem.
            >
            Jon
            >
            I just call a method,  with concatenation of two strings,that takes
            string parameter.  That's all.
            >
            BTW what is wrong with  string x = Foo("foo" + "bar"); ?
            can you please post the signature of method please?

            I guess it is

            public/private void Foo(string)


            -Cnu

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: compiler error: cannot convert type void to string

              On Oct 8, 4:43 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
              I just call a method,  with concatenation of two strings,that takes
              string parameter.  That's all.
              I'm afraid I don't believe you. Please post a short but complete
              program that demonstrates the problem.
              BTW what is wrong with  string x = Foo("foo" + "bar"); ?
              If Foo is declared to be void, then you can't assign a string variable
              based on the result, because there isn't one.

              Jon

              Comment

              Working...