Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

iff statement

Posted on 2004-10-20
4
4,405 Views
Last Modified: 2008-01-09
Hi guys:

I need the syntax of iff statement in C# (if there is one) . thanks
0
Comment
Question by:rxraza
4 Comments
 
LVL 3

Expert Comment

by:aacool
ID: 12359575
The term iff is used for "if, and only if"

There is no single keyword or for iff in C#.

What exactly are you trying to implement with the iff statement?

You might need two if statements to achieve your goal.

In some cases, the effect of iff is achieved internally, .e.g.
MyClass myClass = new MyClass();
if (myClass is MyClass)

{

//executed

}

the is keyword will evaluate to true if and only if the object is of the type MyClass.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 12359753
If you mean VB IIf statement, there is C# equivalent:

VB: str = IIf(result < 0, "less than", IIf(result > 0, "greater than", "equal to"))
C#: str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
0
 
LVL 22

Expert Comment

by:cookre
ID: 12359823
On the off chance you meant 'iif':

boolexpr ? expr1 : expr2

If boolexpr is TRUE, the result is expr1, otherwise the result is expr2
0
 

Author Comment

by:rxraza
ID: 12359969
Thanks guys for the response.

C#: str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));

is what I was looking for.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question