|
With a division, the resulting type is determined based on the type of the operands in much the same way as the ternary operator:
- If both operands are the same type, that is the type of the result;
- If there is an implicit conversion from X to Y, but not from Y to X, then Y is the type of the result;
- If there is an implicit conversion from Y to X, but not from X to Y, then X is the type of the result;
- Otherwise, no result type can be determined, and a compile-time error occurs.
In this case, there is an implicit conversion from Int32 to Nullable<Int32> , but not from Nullable<Int32> to Int32 . Therefore, the type of the result is Nullable<Int32> .
You'll see similar type inference at work with the other binary operators - * , + , - , etc.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The issue isn't the one you think it is. Basically, the problem is the part that says i1/i2. What you have here is a condition that the compiler thinks could return as an int because of the implicit type of this operation. Now, you basically need to tell the compiler that you're returning an int? out of this so that it knows what to put it as. Here's a little trick to demonstrate this:
{ "/", (i1, i2) => ((i2 == 0) ? null : ((int?)i1)/i2) },
|
|
|
|
|
Thanks, Pete !
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Hi guys,
What I'm trying to do is to programmatically open a Excel Worksheet and then within a given range read and analyse all of the tables.
I already know how to open the file and find used range per sheet. But how do I get all the tables from it?
Someone an idea how make this possible? I would be really greatfull.
|
|
|
|
|
Are you using ExcelDataReader[^] ?
If you are, I suggest you study: [^].
What is the problem you are having now with reading/analyzing: more detail please.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
No I'm not. I'm using Open XML to enter the file and to analyse the values of the cells. But I also want to be able to look at the data structure, so if there are tables in the worksheets how do I recognise them.
|
|
|
|
|
Are you opening the XLSX using zip/XML? If yes, then I'd recommend using a library that does that part.
It's quite easy to end up with an incorrect format if one of the references is broken, and there are a lot of dependencies in there
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm implementing some additional features from an already working API for a SignalHound USB Spectrum Analyzer (SA124B).
My code is C#, and i have the SH_API.dll (c or c++).
SHAPI_GetSerNum() & SHAPI_Initialize() are both working.
int initResult = Dll.SHAPI_Initialize();
uint ser = Dll.SHAPI_GetSerNum(0);
However SHAPI_GetSA123CalData is not !
string fileName = "";
int CalDataResult = -1;
CalDataResult = Dll.SHAPI_GetSA124CalData(fileName, 0);
No matter what i set "FileName" to i get the response "0" to CalDataResult. It seems i have some sort of connection to the method in the dll, but there is something going on with this "LPCSTR" filename parameter, that i don't understand !
Can anyone help - how do i sent a LCPSTR from C# to C/C++
-------------------------
The documentation says:
extern "C" __declspec( dllimport ) int SHAPI_GetSA124CalData(LPCSTR filename,int deviceNum=0); //Returns -1 on error
My Wrapper code -----------------------------------
[DllImport("SH_API.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern Int SHAPI_GetSA124CalData(string FileName, int deviceNum=0);
[DllImport("SH_API.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern uint SHAPI_GetSerNum(int deviceNum=0);
[DllImport("SH_API.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int SHAPI_Initialize();
----------------------------------------------------------
|
|
|
|
|
|
Thanks for your support. The result is unfortunately the same (response is always "0"). It doesn't care what I set the filename to or if the file it present. Maybe i'm overlooking something, or that method doesn't really work as the document says.
[DllImport("SH_API.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int SHAPI_GetSA124CalData([MarshalAs(UnmanagedType.LPStr)] string FileName, int deviceNum = 0);
string fileName = "D30510098.bin";
Int32 CalDataResult = -1;
CalDataResult = Dll.SHAPI_GetSA124CalData(fileName, 0);
|
|
|
|
|
I guess you need to go back to the provider of the library and ask them.
|
|
|
|
|
and so i did... and they just confirmed that the API is faulty in that sense, and always reports "0". They will make a new version.
|
|
|
|
|
Hi,
I want to generate an .rtf file in which the data will be filled from the database.
I am short of time to develop my application and dont have time to write my own library for rtf generation.
Any free easy to use library or dll will be helpful.
Please suggest.
Thanks,
Mukul Sharma
|
|
|
|
|
|
mukulsharma1146 wrote: Any free easy to use library or dll will be helpful. ..there's a RichTextBox control in the framework. It is well documented and does exactly what you need.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy,
Thanks for the reply.
Actually I do not have a rich text control in the html. I have form data in the database from which I need to create an rtf report.
As suggested by some other blogs, I am supposed to read the data from the database (SQL Server) and get it inside an HTML form and finally generate the rtf file from the html form (I don't need to render the html form).
Kindly let me know if I am following the right approach.
Also if there are any other ways of achieving this.
Thanks,
Mukul
|
|
|
|
|
You could use the WPF RichTextBoxControl that supports HTML<=> RTF:
"Converting between RTF and HTML" [^].
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
I want to ask how to draw small circle in rectangle?
|
|
|
|
|
|
Needs context. What are you drawing on and with what framework?
Depending on the context, there are several possible answers to your question, and they're so wildly different that if you get the wrong one it won't help you in the slightest.
|
|
|
|
|
How to draw small circle in center of rectangle and how to find center of rectangle?
i have project is object detection base on object shape with method edge detection aforge.net which i use net aforge.net 2.2.4
|
|
|
|
|
I dono haw to write a C# code to upload an image on the image box when button is pressed. plz suggest?
|
|
|
|
|
Upload to where? FTP, a webserver, a database?
What did you try? Have you tried copy/pasting one of the examples on the internet?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
string queryString = "select * from bbb where A1=:A1 and B1=:B1";
public OracleParameter[] GetSqlParameters(string[] fields, object[] obj)
{
try
{
OracleParameter[] parameters = new OracleParameter[obj.Count()];
for (int i = 0; i < obj.Count(); i++)
{
parameters[i] = new OracleParameter(fields[i], obj[i]);
}
return parameters;
}
catch
{
return new OracleParameter[] { };
}
}
how to use this method?give a example!
thinks!
|
|
|
|
|
Ask the person who wrote it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|