convert error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eddy de boer

    #1

    convert error?

    Dear reader,

    In my code I get the following error:

    AddComment.cs(3 2): The best overloaded method match for
    'WebLogger.Mess age.SelectMessa ge(string, out string, out string)' has some
    invalid arguments

    This is the code:


    class Message
    {
    ...
    public int SelectMessage(s tring pID, out string pTitle, out string
    pAddedDate)
    {
    ...
    }
    }

    class AddComment
    {
    ...
    public void InsertComment(i nt pMessageID, string pAuthor, string pEmail,
    string pComment)
    {
    string msgTitle, msgAddedDate;
    Message msg = new Message();
    msg.SelectMessa ge(pMessageID, out msgTitle, out msgAddedDate);
    }
    }

    Does anybody have an idea?
    I'm quite new to C#, so this could easily be something stupid.

    Thanks in advance,

    Eddy de Boer


  • Tom Porterfield

    #2
    Re: convert error?

    eddy de boer wrote:[color=blue]
    > Dear reader,
    >
    > In my code I get the following error:
    >
    > AddComment.cs(3 2): The best overloaded method match for
    > 'WebLogger.Mess age.SelectMessa ge(string, out string, out string)' has some
    > invalid arguments
    >
    > This is the code:
    >
    >
    > class Message
    > {
    > ...
    > public int SelectMessage(s tring pID, out string pTitle, out string
    > pAddedDate)
    > {
    > ...
    > }
    > }
    >
    > class AddComment
    > {
    > ...
    > public void InsertComment(i nt pMessageID, string pAuthor, string pEmail,
    > string pComment)
    > {
    > string msgTitle, msgAddedDate;
    > Message msg = new Message();
    > msg.SelectMessa ge(pMessageID, out msgTitle, out msgAddedDate);
    > }
    > }
    >
    > Does anybody have an idea?
    > I'm quite new to C#, so this could easily be something stupid.[/color]

    SelectMessage requires a string as the first parameter, you are trying to
    pass in int (pMessageID). You need to convert that int to a string first,
    easily done by using pMessageID.ToSt ring().
    --
    Tom Porterfield

    Comment

    • Morten Wennevik

      #3
      Re: convert error?

      Hi,

      InsertComment uses

      int pMessageID

      but SelectMessage uses

      string pID

      Either change SelectMessage to use int pID, or use pMessage.ToStri ng() when calling SelectMessage



      On Tue, 24 May 2005 14:34:06 +0200, eddy de boer <eddy de <boer@discussio ns.microsoft.co m>> wrote:
      [color=blue]
      > Dear reader,
      >
      > In my code I get the following error:
      >
      > AddComment.cs(3 2): The best overloaded method match for
      > 'WebLogger.Mess age.SelectMessa ge(string, out string, out string)' has some
      > invalid arguments
      >
      > This is the code:
      >
      >
      > class Message
      > {
      > ...
      > public int SelectMessage(s tring pID, out string pTitle, out string
      > pAddedDate)
      > {
      > ...
      > }
      > }
      >
      > class AddComment
      > {
      > ...
      > public void InsertComment(i nt pMessageID, string pAuthor, string pEmail,
      > string pComment)
      > {
      > string msgTitle, msgAddedDate;
      > Message msg = new Message();
      > msg.SelectMessa ge(pMessageID, out msgTitle, out msgAddedDate);
      > }
      > }
      >
      > Does anybody have an idea?
      > I'm quite new to C#, so this could easily be something stupid.
      >
      > Thanks in advance,
      >
      > Eddy de Boer
      >
      >
      >[/color]



      --
      Happy coding!
      Morten Wennevik [C# MVP]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: convert error?

        <=?Utf-8?B?ZWRkeSBkZSB ib2Vy?= <eddy de
        boer@discussion s.microsoft.com>> wrote:[color=blue]
        > In my code I get the following error:
        >
        > AddComment.cs(3 2): The best overloaded method match for
        > 'WebLogger.Mess age.SelectMessa ge(string, out string, out string)' has some
        > invalid arguments[/color]

        Well, pMessageID is an int, and you're trying to pass it in as a
        string. What do you want to do with it? You could call ToString() on
        pMessageID if you want:

        msg.SelectMessa ge(pMessageID.T oString(),
        out msgTitle,
        out msgAddedDate);


        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...