|
Hint:
string number = "1234567890";
foreach (char c in number)
{
Console.WriteLine(c);
}
Another Hint:
int iNum = 0;
string strNum = "1234567890";
if (int.TryParse(strNum, out iNum))
{
Console.WriteLine(iNum);
}
|
|
|
|
|
You could try the following.
ConsoleKeyInfo ck = Console.ReadKey();
char Key = ck.KeyChar;
|
|
|
|
|
Try this:
public void test()
{
try
{
Console.WriteLine("Please enter the variables : ");
Int32 valueOne = ConvertLine(Console.ReadLine());
Int32 valueTwo = ConvertLine(Console.ReadLine());
Console.WriteLine("Answer : {0}", valueOne + valueTwo);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Message : {0}", e.Message); Console.ReadLine();
}
}
private int ConvertLine(string value)
{
try
{
if (String.IsNullOrEmpty(value) == false)
{
return Convert.ToInt32(value);
}
Console.Error.WriteLine("Empty field is not supported : default value used 0");
}
catch (Exception exception)
{
Console.Error.WriteLine(String.Format("{0} : default value used 0", exception.Message));
}
return 0;
}
|
|
|
|
|
I have a problem with a webbrowser control not displaying an image from the local harddrive of the Windows Mobile 5 PocketPC I have.
Basically I am writing the HTML code to the browser:
webBrowser.DocumentText = @"
<html>
<body style='text-align: center; margin-left: auto; margin-right: auto'>
<img src='" + AppPath + @"\loading.gif' />
</body>
</html>";
The AppPath is:
private string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
Now I had it throw a message box before that and it gives: "\Program Files\Mobile Inventory" which if you add \loading.gif on that it would be correct. I have even verified that the loading.gif image file was in that location and it was.
It still just shows a red X. If you are wondering why I am doing it this way instead of a picture box it is because a picturebox on win mobiile cannot display animation. (Nice huh)
|
|
|
|
|
This may not be the answer, but I had similar problems with ASP.NET, and resolved it when I realized all paths are relative to the page current directory.
You can try replacing the AppPath with "~" for a web-centric root, or
Use "<%= Page.ResolveUrl("~")%>" in the path, and it all resolves in ASP.NET:
Resources/Images/Logos/myLogo.gif" />
(and yes, I know the double quotes don't look right - works though.)
Gotta be worth a try.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I didnt have any luck with that.
<img src="<%= Page.ResolveUrl("~")%>Resources/Images/Logos/myLogo.gif" />
doesn't work because of the quotes. Using the quotes ends the string line. I did try:
<img src='<%= Page.ResolveUrl('~')%>Resources/Images/Logos/myLogo.gif' />
But was unable to get that to work. I also tried just this:
<%= Page.ResolveUrl('~')%> to see if it would just print the URL it resolved and it prints nothing.
I also tried this:
<img src='/Program Files/Mobile Inventory/loading.gif' />
Which is the exact path and it still won't work! I also tried:
<img src='loading.gif' />
LOL.. so frustrating! It shoul be easy! This is a Windows Mobile version 5 (not 6) barcode scanner
|
|
|
|
|
As Griff said, plus you may have a problem with the (back)slashes: don't mix backslashes and forward slashes, and I tend to have more luck with forward slashes in HTML.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Copying an example I found, I have a Windows application with no main form that just manages a NotifyIcon in the tray with its small context menu functions. As such, its Main has Application.Run() instead of Application.Run(someform) . That part works fine.
Now I need it to conditionally show/hide a form. There are no user interaction controls on the form (it's display only) and the "default" condition is to have the form hidden. If I use Form.ShowDialog() , the form appears, but blocks the user interaction that is associated with the NotifyIcon.ContextMenu and I have no way to remove it. If I use Form.Show() to keep the user interaction with NotifyIcon functional, the form appears but none of its contained controls render and it forever shows the Wait cursor.
After much fruitless searching for a threading issue (even though InvokeRequired is always false), I came across a clue that it might instead be a message pump issue. This makes some sense (since I can fully show and hide the form if I do it within the ContextMenu event handlers), but I can't find enough info to compose a candidate solution.
How do I get this form to complete its rendering without making it modal?
|
|
|
|
|
I found something that works, but I'd like to know if this was really the preferred solution since it seems a bit awkward to me. However, this solution does support the message pump hypothesis I mentioned in my question.
In the constructor for the form that I want to display, I start up an auto-reset Timer that fires every 200 (for now) ms. In the timer event handler, I call Application.DoEvents() . That's all it took... a surrogate message pump!
Additionally, the Show, Hide, Close, and content update actions all had to be wrapped with Invoke boilerplate, but that makes sense.
Wildly simple, but was there a better way? If I had two forms to show, would each require its own timer solution?
|
|
|
|
|
|
|
When he did that yesterday, it got his article a good crop of 1 votes. So he does it again today.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Another lame attempt at self-promotion
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Your article sucks. Is that what are waiting to read? Don't you understand replies to your previous post?
I haven't even seen the article nor voted it.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Dude, you really got some nerve to start all that
|
|
|
|
|
You need to wait for your article to be open to everybody. People will rate your article based on its content. Currently the majority of members cannot see your article. You just need to be patient.
|
|
|
|
|
I think that you should let your article speak for itself.
|
|
|
|
|
Hello,
i need to import a win32 (unmanaged) dll in C#, can it be done and what would be the best way to do it?
TY
|
|
|
|
|
Hi,
I don't know about importing a DLL, however you can call unmanaged functions using P/Invoke.
I have been writing this little article[^] on the subject, it isn't finished yet, but it may offer an introduction.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, when do we get it on regular forums?]
|
|
|
|
|
Ref. PInvoke, there's a good wiki available;
pinvoke.net/[^]
Rhys
"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance."
Terry Pratchett
|
|
|
|
|
it can be done as described in the others answers, but consider it is a lot of writing boring code so really think what you need and what not. Because degrees performance, consider writing a wrapper dll which will do some stuff.
Tip: Strings with StringBuilder and size as parameter
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
which dll you want to use?
Is it system dll or else?
|
|
|
|
|
Hi guys
I am simply trying to profile a sine function I created against Math.Sin(). From checking around using the DataTime.Now structure seems to be the one ppl mention to use. But when I profile and get the Tick values before and after they are the same !! even If I call the function multiple times ? I would be sure that the values would have been updated no !! Is there another source from which to get the system time in milliseconds ?
here is the code anyway ??
Thanks
static void Main(string[] args)
{
Sin mySin = new Sin();
double sinValue = 39 * (Math.PI / 180);
long before = DateTime.Now.Ticks;
double good = Math.Sin(sinValue);
long after = DateTime.Now.Ticks;
long result = after - before;
Console.WriteLine("Sin for {0} = {1}", sinValue, good);
Console.WriteLine("Time taken : {0}", result);
before = DateTime.Now.Ticks;
double bad = mySin.SinFunction(sinValue , 6);
after = DateTime.Now.Ticks;
result = after - before;
Console.WriteLine("MySin for {0} = {1}", sinValue, bad);
Console.WriteLine("Time taken : {0} ", result);
Console.ReadLine();
}
|
|
|
|
|
Why isn't your own sine static?
How about this (untested)
edit: of course you should use the StopWatch class but I'm a bit lazy right now (sorry)
static void Main(string[] args)
{
Sin mySin = new Sin();
double sinValue = 39 * (Math.PI / 180);
long before = DateTime.Now.Ticks;
double good;
for (int i = 0; i < 10000; i++)
good = Math.Sin(sinValue);
long after = DateTime.Now.Ticks;
long result = after - before;
Console.WriteLine("Sin for {0} = {1}", sinValue, good);
Console.WriteLine("Time taken for 10k : {0}", result);
before = DateTime.Now.Ticks;
double bad;
for (int i = 0; i < 10000; i++)
bad = mySin.SinFunction(sinValue , 6);
after = DateTime.Now.Ticks;
result = after - before;
Console.WriteLine("MySin for {0} = {1}", sinValue, bad);
Console.WriteLine("Time taken for 10k : {0} ", result);
Console.ReadLine();
}
|
|
|
|
|