|
Dear all,
I have a little problem converting a string that contains a ',' into a double.
Double needs a value devided by a dot ( or so I've read )
So , in my code , the following occurs :
string lat = p[u].X.ToString().Replace(',', '.');
MessageBox.Show(lat);
The output will be for example : 55.38978 ( which shows up perfect in the messagebox )
However, if i do the following :
MessageBox.Show(Convert.ToDouble(lat).ToString());
The output will be : 5538978
That doesn't make a whole lot of sense to me. So that dot is somehow bothering Double or am I not converting properly ?
Cheers
|
|
|
|
|
Well the problem is that double works with a komma in stead of a dot.
See it like this:
string ss = "55,5493";
string lat = ss.ToString().Replace(',', '.');
double d = Convert.ToDouble(ss);
double dd = Convert.ToDouble(lat);
MessageBox.Show("" + d);
MessageBox.Show("" + dd);
So you should change this one:
string lat = ss.ToString().Replace(',', '.');
into this one:
string lat = ss.ToString().Replace('.', ',');
Good luck
|
|
|
|
|
Hi Rick,
ToString() when applied to numbers will by default use the regional settings of your system,
which define a "decimal point" (not necessarily a period) and a "thousands separator" (not
necessarily a comma).
Parse() and TryParse() will observe the "decimal point" and ignore the "thousands separator".
If you have a number formatted one way (say West-European way, with decimal comma, and thousands
period) and parsed another way (say US way), you will get wrong results, and even an Exception
when more than one thousands separator is present.
The solution is NOT to replace periods by comma and vice versa, the solution is to apply
the appropriate settings, by using a FormatProvider or CultureInfo.
The above applies not only to doubles, but also to floats and decimals.
|
|
|
|
|
How do I write the contents of a webpage without a webbrowser? I am aware of
webBrowser.Navigate("http://www.google.com");
using (StreamWriter sw = File.CreateText(path))
{
sw.Write(webBrowser.DocumentText);
}
However, I was trying to use another way to do it without using a webBrowser.
Thanks in advance.
|
|
|
|
|
Hi,
have a look at WebRequest and HttpWebRequest classes and the GetResponse method.
|
|
|
|
|
In my application, when I showing a new form I do,
Form2 frm2=new Form2();
This.hide();
frm2.TopMost = true;
frm2.Show();
I do like that..again when I come to first form. I do the same being in second form.(imagine I am in Form2 now.)
this.Close();
frm1.Show(); // this is my first form.
Problem is some times I cant see my first form.it is still hiden. So it is happens sometimes.
Are there any way to know (some status) to know my form is already hiden or shown.
What is the best practice of this kind of situation?
|
|
|
|
|
Hi,
Show/Hide methods and Visible property always correspond.
|
|
|
|
|
Dear All,
To know the IEnumerable Interface I have done one demo Aplication please let me know whether there is anything wrong in my approach.
class MyFile : FileSystemInfo
{
private FileInfo _strFile;
public MyFile(FileInfo strFile)
{
_strFile = strFile;
}
public override void Delete()
{
_strFile.Delete();
}
public override bool Exists
{
get
{
if (_strFile.Exists)
{
return true;
}
else
{
return false;
}
}
}
public override string Name
{
get { return _strFile.Name;}
}
}
class MyFiles : IEnumerable<MyFile>
{
private string _directoryPath;
private string _fileExtension = "xml";
public MyFiles(string directoryPath)
{
_directoryPath = directoryPath;
}
public string FileExtension
{
get { return _fileExtension; }
set { _fileExtension = value; }
}
#region IEnumerable<MyFile> Members
public IEnumerator<MyFile> GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
}
Here is it's implementation :
static void Main()
{
MyFiles myFS = new MyFiles(@"D:\TestInterface");
foreach(MyFile FS in MyFiles)
{
Console.WriteLine(FS.Name);
Console.ReadLine();
}
}
Here I am trying to Iterate the Files in Certain directory, and it's further implementation would be to Add New Methods to MyFile Class so as to get Certain required Data from the Files.So far it looks good .
I only wanted to know whether my Interface Implementation is Wrong anywhere or require any changes.
Thanks in Advance.
Develop2Program & Program2Develop
|
|
|
|
|
Navneet Hegde wrote: IEnumerator IEnumerable.GetEnumerator()
You dont really need to provide an implementation for that too. Simply return the generic IEnumerable, ie: return GetEnumerator();
Everything else looks fine
|
|
|
|
|
Please provide an example.
Thank You
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
delegate types are sealed, so no.
|
|
|
|
|
You can 'modify' a delegate though. As an example, see how I make Action delegates parallel in my latest article[^].
|
|
|
|
|
I still like that article. I still cannot think of a single instance where I'd use it, but who cares because it's cool.
|
|
|
|
|
Pete O'Hanlon wrote: I still cannot think of a single instance where I'd use it, but who cares because it's cool.
I want to make it even cooler, by taking any delegate type, then generating a DynamicMethod to do the same as I do with the Action delegates.
|
|
|
|
|
Ooohh... Nice. Still coming up blank as to when I would use it. The race is now on to find day to day practical uses.
|
|
|
|
|
Pete O'Hanlon wrote: Still coming up blank as to when I would use it.
With all the news about multicore CPU's, it could be handy anywhere
|
|
|
|
|
All delegates are derived from System.Delegate . But compiler won't allow you to derive from this class, it is done internally. You can always cast any user defined delegates to "System.Delegate" type.
|
|
|
|
|
I am working on CLient/Server Multithreaded messenger built on .Net 2.0 using C# WINFORM. and the classes for communication I am using are TCPListener and TCPClient.
The problem i am facing is that, when i connect two user on remote PCs then if User1 changes the Desktop's theme on its PC while keep the Client-Application open/running and meanwhile User2 send data to User1 then the Client-Application of User1's PC get halted and Server is no more responsive for any activity.
Feedback is higly appreciated....Thnks in advance.
Syed Raheel Noor
Software Developer
|
|
|
|
|
Hi All,
I am not a pro developer, and all of my coding experience has been spent creating small class libraries and functions to be called from applications. In that time I've developed a reasonable grounding in C# coding mechanics and am comfortable with that.
However, I have envisioned a requirement that means I need to code a complete application and user interface, which I've never done before - or seen source code for. In considering the problem I realise that it's something that is easy to screw up, especially if your expectations of the end product are above average.
Given that, i am wondering whether there is a book out there that effectively documents the process of designing and coding a non-trivial application. That way, I would have my way illuminated somewhat as I begin this endeavour.
Does anyone have any suggestions? is my requirement clear? All help and advice will be warmly received.
Regards,
Dave
modified on Monday, July 7, 2008 5:26 AM
|
|
|
|
|
Hmmn. Does the lack of replies mean that this type of resource doesn't exist?
Regards,
Dave
|
|
|
|
|
Hello everyone,
I am using the following commands in Windbg to debug the following simple application, why there is error like, "Note: this object has an invalid CLASS field
Invalid object"?
0:004> ~0e!clrstack -a
OS Thread Id: 0x1194 (0)
Child-SP RetAddr Call Site
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
RSP/REG Object Name
000000000012efe0 0000064280150182 TestDebugManaged1.Program.foo()
PARAMETERS:
this = 0x0000000002651ac8
LOCALS:
0x000000000012f000 = 0x0000000000000064
0x000000000012f004 = 0x0000000000000001
RSP/REG Object Name
000000000012f020 000006427f67d4a2 TestDebugManaged1.Program.Main(System.String[])
PARAMETERS:
args = 0x0000000002651aa8
LOCALS:
0x000000000012f040 = 0x0000000002651ac8
0:004> !do 0x000000000012f000
<Note: this object has an invalid CLASS field>
Invalid object
0:004> !do 0x000000000012f004
<Note: this object has an invalid CLASS field>
Invalid object
namespace TestDebugManaged1
{
class Program
{
void foo()
{
int a = 100;
while (true)
{
Thread.Sleep(10000);
a++;
}
}
static void Main(string[] args)
{
Program instance = new Program();
instance.foo();
return;
}
}
}
thanks in advance,
George
|
|
|
|
|
Why do you keep asking questions like this ? What bizarre research project are you on that you don't seem to write any *real* code, you do no research of your own, but you ask the most indepth, obscure and ultimately pointless questions here ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Sorry Christian.
For this question, actually I have did some research, but you know there are very few documents about WinDbg...
regards,
George
|
|
|
|
|
The best docs I have found is from blog postings on blogs.msdn.com.
|
|
|
|
|
Thanks leppie,
blogs.msdn.com is a very big site.
Any specific links or?
regards,
George
|
|
|
|