473,765 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type of conditional expression cannot be determined because there is no implicit conv

2 New Member
what is that mean its come when i do terrary operator ith conso;.writelin e operation
Jul 15 '10 #1
4 3288
Christopher Nigro
53 New Member
No one caqn help you unless you show your code. Otherwise, it means exactly what it says.
Jul 15 '10 #2
thushan
2 New Member
Expand|Select|Wrap|Line Numbers
  1. static void Main(string[] args)
  2.         {
  3.  
  4.             int n = 1;
  5.             int m = n < 10 ? Console.WriteLine("1") : Console.WriteLine("2"); 
  6.  
  7.             Console.WriteLine("m={0}", m);
  8.           Console.ReadLine();
  9.  
  10.  
  11.         }
  12.  
this is my code im beginer to c#
Jul 16 '10 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
Oh, it's 'cause you're trying to assign an integer with the return value of a Console.WriteLi ne(...) call, which happens to be void.

That little ?: thing is a replacement for if/else.

Expand|Select|Wrap|Line Numbers
  1. (boolean test) ? (true statements) : (false statements)
... is exactly equivalent to ...

Expand|Select|Wrap|Line Numbers
  1. if (boolean test)
  2.   (true statements)
  3. else
  4.   (false statements)
So what your statements come out to be is this...

Expand|Select|Wrap|Line Numbers
  1. int n  = 1;
  2. int m;
  3. if (n < 10)
  4.   m = Console.WriteLine("1");
  5. else
  6.   m = Console.WriteLine("2");
  7.  
  8. ...
In all cases, you'll need to ditch the Console.WriteLi ne if you want to assign a value to m. If you want m to be an integer, then just have..

Expand|Select|Wrap|Line Numbers
  1. int m = n < 10 ? 1 : 2;
If you want the Console.WriteLi ne part, skip assignment and write the full if/else statement.

Hope that helps.
Jul 16 '10 #4
a1ashiish
1 New Member
Thanks Gary, you made the things very easy for beginners. I also want add some text on ternary operations - if you follow the MSDN for ternary operation you will find that "either the type of first expression & second expression must be same, or an implicit conversion must exist from one type to other".
It means both the expressions in ternary operation must return same type.
Dec 26 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
1514
by: Elaine Jackson | last post by:
If bool(B_i)==True for 1<=i<=n and j is the smallest i with bool(A_j)==True, then the evaluation of (A_1 and B_1) or ... or (A_n and B_n) returns B_j without evaluating any other B_i. This is such a useful mode of expression that I would like to be able to use something similar even when there is an i with bool(B_i)==False. The only thing I can think of by myself is ( (A_1 and ) or ... or (A_n and ) ), and I can't be satisfied with that for...
1
5921
by: neutrinman | last post by:
why does the following error occur? def quit_time(): data_file = shelve.open("data.dat", "c") data_file = datetime.datetime.today() print data_file raw_input("enter") Traceback (most recent call last):
3
3331
by: João Santa Bárbara | last post by:
Hi all this message ( Expression cannot be evaluated at this time. ) apears when i in the debug window do this ?xdrMaster("field1") can some one help me .. JSB
3
7477
by: Patrick Dugan | last post by:
I am *trying* to convert a VB6 program to vb.net. One error I am getting that I cannot figure out is: 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type. This is the offending line where the error is located: res = UUIRTSetReceiveCallback(hDrvHandle, AddressOf IRReceiveCallback, Me)
4
1925
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there are NO classes in the Classes collection (Classes) of the custom object. The conditional expression returns the error shown below it... =======================================================XML returned by
12
8094
by: paul | last post by:
Hi everyone, I'm debugging an FFT routine and it has thrown up a perplexing error which I cannot trace. Cannot anyone help? I've included the relevant code below with comments: rlft3(data_in1, speq_out1,1,512,256,1); // Perform FFT on 1st set of input data rlft3(data_in2, speq_out2,1,512,256,1); // Now 2nd set
4
360
by: chandanlinster | last post by:
consider the following program: #include <stdio.h> #include <stdlib.h> int main(void) { int i; double f;
1
1439
by: Amit Shrestha | last post by:
I recently designed report card management system for a college. I'm having a problem with conditional expression. If a student received less than 35 in a particular subject, I wanted "fail" to be printed in the sum or total. I used Dcount function but it counted all the records in the table rather than the report. Count function counted all the records in the report but i could not use the criteria. So some body please help me out.
3
1826
by: somenath | last post by:
Hi All, I got some questions regarding the type of expression . For example 1)char *const *(*ptr)(); Here the type of ptr is it is constant pointer to a function which accept unspecified number of argument and returns char * 2) char *const *(ptr1)();
1
5484
by: Sep410 | last post by:
Hello, Here is the code that I have : If Not Val(dgFamilyMember.Rows(i).Cells(15).Value).Equals(Val(publicFamilyMemebrDS.Tables(0).Rows(i).Item(15).ToString)) Then StrFMCommet &= " FM Group: " & publicFamilyMemebrDS.Tables(0).Rows(i).Item(14).ToString & "" StrFMCommet &= " Changed to " & dgFamilyMember.Rows(i).Cells(14).Value & " *** " If flagClientDetailFMUpdated = False...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.