Results 1 to 6 of 6

Thread: [RESOLVED] IIF in VB.NET....C# = ???

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Resolved [RESOLVED] IIF in VB.NET....C# = ???

    VB Code:
    1. Dim Growl As String = "This is some data"
    2. Dim Woof As String = IIf(Growl.Trim = String.Empty, "Hi", "Bye")

    What I have in C# is:
    Code:
    string Growl = "MyData";
    string Woof = (Growl.Trim() = string.Empty ? "Hi" : "Bye");
    But it squiggly blue lines the string.empty and says cannot convert to boolean.

    Any ideas?

    Woof

  2. #2

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: IIF in VB.NET....C# = ???

    fat lot of use you lot were

    Code:
    string Username = "MyData";
    string Woof =(Username.Trim().Equals(string.Empty) ? "Hi" : "Bye");
    Fixed

    Woof

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] IIF in VB.NET....C# = ???

    That's because yuo are using an assignment operator instead of an equality operator. You need this:
    Code:
    string Woof = (Growl.Trim() == string.Empty ? "Hi" : "Bye");
    One "=" is assignment, two "=" is equality.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] IIF in VB.NET....C# = ???

    A nineteen minute turn-around isn't too bad. I still haven't recovered from your collection thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: [RESOLVED] IIF in VB.NET....C# = ???

    My collection class works perfectly..maybe a little unorthadox, but it wrks
    I have an updated class now...you know I never do anything by halves

    Woof

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