|
Basically, you can't do this. This is because you're evaluating an expression (bool?x:y) that is trying to return 2 different types, an object reference and int.
From the MSDN Gospel:
The second and third operands of the ?: operator control the type of the conditional expression. Let X and Y be the types of the second and third operands. Then,
If X and Y are the same type, then this is the type of the conditional expression.
Otherwise, if an implicit conversion exists from X to Y, but not from Y
to X, then Y is the type of the conditional expression.
Otherwise, if an implicit conversion exists from Y to X, but not from X
to Y, then X is the type of the conditional expression.
Otherwise, no expression type can be determined, and a compile-time error occurs.
What all this means, is that the compiler error occurs because there is no conversion possible between int and null . It looks like you'll have to do it using an if statement.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
This solved it, thank you very much =)
-- modified at 16:50 Monday 12th December, 2005
|
|
|
|
|
hi,
i want to save a picture in the ico-format and tried it like this:
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
Bitmap bmp = new Bitmap(16, 16);<br />
Graphics g = Graphics.FromImage(bmp);<br />
<br />
Font f = new Font("Arial", 5);<br />
LinearGradientBrush b = new LinearGradientBrush(ClientRectangle, Color.Red, Color.Red, LinearGradientMode.Horizontal);<br />
g.DrawString("ABC", f, b, 1, 1);<br />
pictureBox1.Image = bmp;<br />
<br />
bmp.Save("d:\\test.ico", ImageFormat.Icon);<br />
Icon = new Icon("d:\\test.ico");<br />
}
somehow it doesn't work, i just don't have a clue what the reason is.
i hope someone can help me.
|
|
|
|
|
Hi man try this:
System.IO.FileStream stream = System.IO.File.Create(@"c:\myIcon.ico");
Icon ico= System.Drawing.Icon.FromHandle(bmp.GetHicon());
ico.Save(stream);
hope that helped
GanDad
|
|
|
|
|
I have a grid control that takes an IList, ITypedList or IBindingList object as a DataSource. I'm currently using a System.Data.DataTable and the performance is pretty dismal. I've isolated the bottle neck as being the build of the DataTable. My question is, which of the various data collections is the lightest weight and most efficient? Thanks.
-- modified at 14:10 Thursday 8th December, 2005
|
|
|
|
|
An IList implementation is the lightest of the three. But, why is filling your DataTable taking so long? I ask because if it's an inefficient process, you'll run into the same lag when filling an IList object.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 17:18 Thursday 8th December, 2005
|
|
|
|
|
Hi everyone!
I got a little problem with an asyncronous WebRequest, or more precise, with its exception handler.
I'm calling a method that issues an asyncronous WebRequest and returnes its IAsyncResult to be able to wait for it lateron. Everything works fine so far, but if the host is unreachable an exception is thrown and an error message is added to my RequestState, which is returned along with the IAsyncResult. The problem is that in many cases that error message is added to the RequestState after my surrounding class received and waited for the WebRequests IAsyncResult.WaitHandle (which of cause is compleated and no error messages are found). So i'm trying for quite a while now to, 'sort of', syncronize that mechanism with a ManualResetEvent inside an asyncronously called delegate whose IAsyncResult is returned instead of the WebRequests IAsyncResult, but with no success.
I'm not very familiar with threaded applications, so i don't know exactly what to look for... so it would be great if someone could point me in the right direction.
Thanks in advance!
Below some pseudo-code with the general structure:
public void CallingMethod()<br />
{<br />
<br />
<br />
}<br />
<br />
public IAsyncResult Process()<br />
{<br />
IAsyncResult asyncResult = myWebRequest.BeginGetResponse(RespCallback, myRequestState);<br />
return asyncResult;<br />
}<br />
<br />
private void RespCallback(IAsyncResult asyncResult)<br />
{<br />
try<br />
{<br />
resp = req.EndGetResponse(asyncResult);<br />
}<br />
catch (Exception ex)<br />
{<br />
string errorMessage = string.Format("host unreachable...");<br />
((MyRequestState)asyncResult.AsyncState).AddStatusMessage(errorMessage);<br />
}<br />
}
Variables won't; constants aren't. (Osborne's Law)
|
|
|
|
|
Is is possible to have a C# app update text boxes in a webpage that I don't own?
For example if there was a webpage that had a couple of textarea input fields would it be possible to write a C# app that could put text into those textarea's?
Thanks.
- Aaron
|
|
|
|
|
Hi Aaron,
Do you actually need to do this? Perhaps if you are wanting to send data to a particular website you could simulate the POST with HttpWebRequest ...?
Regards,
Rob Philpott.
|
|
|
|
|
Yes, it is something I would like to do. Would it be possible to provide and example using the HttpWebRequest? I'm not very familiar with web programming.
Thanks.
- Aaron
|
|
|
|
|
Hi again,
The first thing I'd do in tackling this problem is to see what the form the POST takes when you fill in the details on the webpage normally by hand and hit submit.
I'd recommend using the Microsoft Soap Toolkit Trace Utility for this http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en[^]
Fire this up and create a new trace. Put in the URL of the page you want to submit to, and leave the local port on 8080 and the external port on 80. Then point your browser at http://localhost:8080
This tool will allow you to see exactly what gets sent and what is recieved from the website (provided its not SSL secured). From playing around with this you should be able to determine exactly what to POST to the website to make it look like its just plain Internet Explorer etc. I find this is a damn handy thing to have around when web programming. Bear in mind that this is a bit like the old screen-scraping approach and if the website changes will probably break.
In your code create an instance of the HttpWebRequest class by calling its static Create() method passing in the url of the website. Set the Method property to "POST" and then use GetRequestStream() to get a stream to which you can feed your simulated data. Call GetResponse() to fire the data up to the website.
If you have problems with this I'll knock up a sample for you tomorrow.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks a lot for the response Rob. I'll give this a try tomorrow to see if I can do what you say, if not maybe I'll take you up on the sample you might be able to give me.
Thanks again for the help it's very appreciated.
- Aaron
|
|
|
|
|
Hi Rob,
I'm trying to make a simple sample to test this on, but I'm not sure what I should put in the FORM tags ACTION attribute. Can I just put anything I want in there or does it actually have to go to something that will process the information?
Thanks very much for the help on this issue.
- Aaron
|
|
|
|
|
Hi again Rob,
Sorry to keep bothering you, but I think I'm a little out of my depth here so if there's anyway you could knock up a sample for me to take a look at I would appreciate it very much.
Thanks.
- Aaron
|
|
|
|
|
Hello,
Your prb looks very uncommon to me. Webapplication really expects the data to be submitted manually through the browser. If at all it needs to be automated, generally we will have webservice to accept the data.
Hope this helps!
-A
Work smarter, not harder
|
|
|
|
|
I would like to ask why break statements cannot have labels in C#?
For instance;
<code>label1:
for(;;)
{
label2:
for(;;)
{
label3:
for(;;)
{
break label2;
}
}
}</code>
Kind Regards,
Sarp Arda Coskun
-- modified at 12:47 Thursday 8th December, 2005
|
|
|
|
|
What for would you need this?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
As far as I know Java have this. And it could be beatiful to goto label2 directly for example. Not only a break to one outer loop.
Sarp Arda Coskun
|
|
|
|
|
You could still use goto , but remember:
For every goto you use, god kills a kitten!
mav
|
|
|
|
|
For god's shake...i haven't used goto since :
Amstrad 6-128
BASIC 1.1
Ready
|
Aaaaahh beautiful recollections of my childhood.
|
|
|
|
|
Perl does it and it makes sense to me. *shrug*
---
Shawn Poulson
spoulson@explodingcoder.com
|
|
|
|
|
C# is a post C++ and Java language, It took the good from both languages. using labels in code makes it unreadable, using labels is not a good idea. Thats y they got rid of so called labels.
Work smarter, not harder
-- modified at 16:55 Thursday 8th December, 2005
|
|
|
|
|
C# has labels and goto statements but not allow labels with break statements.
However, I also agree on that it decreases the readibility of the code.
|
|
|
|
|
Man, what you're asking for is damn ugly. If Java has this, I'm glad I don't use Java.
Christian Graus - Microsoft MVP - C++
|
|
|
|