Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] ForEach Question

  1. #1

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Resolved [RESOLVED] [2.0] ForEach Question

    What is wrong here:

    Code:
               char[] InvalidsArray = Path.GetInvalidFileNameChars();
    
               foreach (char x in InvalidsArray)
               {
                   if (newName.Contains(x.ToString))
                   {
                       return false;
                   }
               }
               return true;
    The line ' if (newName.Contains(x.ToString))' gives me this error 'Error 1 The best overloaded method match for 'string.Contains(string)' has some invalid arguments'

    x is converted to a string, right? So what am I doing wrong?

    Thanks!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2.0] ForEach Question

    You need the () at the end of ToString, otherwise the compiler thinks you're refering to the actual ToString method rather than the result it returns.


    C# Code:
    1. char[] InvalidsArray = Path.GetInvalidFileNameChars();
    2.  
    3.            foreach (char x in InvalidsArray)
    4.            {
    5.                if (newName.Contains(x.ToString()))
    6.                {
    7.                    return false;
    8.                }
    9.            }
    10.            return true;
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: [2.0] ForEach Question

    Thank you for not prefacing your answer with 'DUH!'

    I don't know how I missed that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width