473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

iif and type inference

Hello,

Is there a way in VB.NET to do something like

dim myInt = if foo() then bar(3) else 4

and have the compiler infer that myInt is an Integer, since bar()
returns an integer and 4 is an integer?

Thanks a lot for any info.

Maurizio
Jul 17 '08 #1
7 1192
No, there is not a short equivalent of if-else in VB.NET as there is in C#
(condition ? true : false) but if you are sure that both statements return
an object of the same type, you can cast the result of IIf: CInt(IIf(foo(),
bar(3), 4)) in your case.

Best Regards,
Stanimir Stoyanov | www.stoyanoff.info

"Maurizio Colucci" <ma**************@gmail.comwrote in message
news:60**********************************@27g2000h sf.googlegroups.com...
Hello,

Is there a way in VB.NET to do something like

dim myInt = if foo() then bar(3) else 4

and have the compiler infer that myInt is an Integer, since bar()
returns an integer and 4 is an integer?

Thanks a lot for any info.

Maurizio
Jul 17 '08 #2
Hello Maurizio,

Since the code is not sooo difficult - why don't you just give it a try?

Best regards,

Martin

On 17.07.2008 16:40, wrote Maurizio Colucci:
Hello,

Is there a way in VB.NET to do something like

dim myInt = if foo() then bar(3) else 4

and have the compiler infer that myInt is an Integer, since bar()
returns an integer and 4 is an integer?

Thanks a lot for any info.

Maurizio
Jul 17 '08 #3
On Jul 17, 12:14*pm, "Martin H." <hk...@gmx.netwrote:
Hello Maurizio,

Since the code is not sooo difficult - why don't you just give it a try?
I'm sorry, I don't think I understand that you mean.

Maurizio
Jul 17 '08 #4
On Jul 17, 12:08*pm, "Stanimir Stoyanov" <stoya...@live.comwrote:
No, there is not a short equivalent of if-else in VB.NET as there is in C#
(condition ? true : false) but if you are sure that both statements return
an object of the same type, you can cast the result of IIf: CInt(IIf(foo(),
bar(3), 4)) in your case.
Thank you, I was afraid that was the only way. It also does not use
lazy evaluation.

Maurizio
Jul 17 '08 #5
Which version ? If VB 2008, you could use the new If function :

Dim myInt = If(foo(), bar(3), 4)

--
Patrice

"Maurizio Colucci" <ma**************@gmail.coma écrit dans le message de
groupe de discussion :
60**********************************...oglegroups.com...
Hello,

Is there a way in VB.NET to do something like

dim myInt = if foo() then bar(3) else 4

and have the compiler infer that myInt is an Integer, since bar()
returns an integer and 4 is an integer?

Thanks a lot for any info.

Maurizio

Jul 17 '08 #6
On Jul 17, 1:15*pm, "Patrice" <http://www.chez.com/scribe/wrote:
Which version ? If VB 2008, you could use the new If function :

* * * * Dim myInt = If(foo(), bar(3), 4)

--
Patrice
That's great! Exactly what I was hoping for. Thanks a lot Patrice.

M
Jul 17 '08 #7

Thank you Nick. That's exactly what I was hoping for. :)

Maurizio

Jul 17 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A.M | last post by:
Hi, Is there any inelisence IDE (like visual studio) for python? Thanks, Alan
0
by: Brett C. | last post by:
My thesis, "Localized Type Inference of Atomic Types in Python", was successfully defended today for my MS in Computer Science at the California Polytechnic State University, San Luis Obispo. With...
39
by: Noticedtrends | last post by:
Can inference search-engines narrow-down the number of often irrelevant results, by using specific keywords; for the purpose of discerning emerging social & business trends? For example, if...
1
by: Ken Cox [Microsoft MVP] | last post by:
Hi, I'm using a dataset to read data from an XML file. I don't control the XML. The XML has no schema and therefore is treated like a string. My data consumer wants the column type to be a...
4
by: Harold Howe | last post by:
I am running into a situation where the compiler complains that it cannot infer the type parameters of a generic method when one of the function arguments is an anonymous method. Here is a...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: Nie longhai | last post by:
I have a generic method in a class as follow: T Get<T>(string key) { ..... return Convert.ChangeType(v, typeof(T)) } when I use it in my code:
12
by: =?Utf-8?B?Z3V5?= | last post by:
What do people here think about VB2008 having the ability to infer type? e.g you can now say Dim i=5 which will create i as an integer Personally I do not like it as it is not consistent and may...
2
by: Chris Dunaway | last post by:
When using linq queries, is it *required* to use type inference? I was reviewing some linq samples and came across this one: public void Linq5() { string digits = { "zero", "one", "two",...
2
by: Maurizio Colucci | last post by:
Hi, I have a function so defined function foo (byval l as List(of IMyInterface)) as bar I have a List(of C), where C implements IMyInterface. I want to pass the list as input to foo, like
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.