|
Not yet, just ask for general advice or better ideas here.
Do you have any ideas?
regards,
George
|
|
|
|
|
George_George wrote: Not yet, just ask for general advice or better ideas here.
The best thing you can do is try things out for yourself before asking. This will enable you to sift answers for yourself, and to evaluate what works and what doesn't. More importantly, you shouldn't rely on people giving you the right answers for many reasons (in no particular order):
They mightn't have understood your problem.
Language issues.
Their information is based on old behaviour that has long been superseded.
They plain got the wrong end of the stick in the first place.
They are just yanking your chain.
They really don't know.
They have only given you part of the picture because they expect you to get the rest for yourself.
You've posted a lot of questions in the past month or so which you could have answered yourself with a well constructed example. Why not try things out for yourself and then post for clarifications on points you don't understand - oh, and buy a book.
|
|
|
|
|
I really wanted to give the answer that they would be the same, but after checking, I found some surprising results. Here is the timing code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Globalization;
namespace CultureInfoKata {
class Program {
static void Main(string[] args) {
Stopwatch st = new Stopwatch();
CultureInfo info = CultureInfo.CurrentCulture;
Int64 iterations = 10000000;
Int32 trials = 20;
TimeSpan rAverage = TimeSpan.Zero;
TimeSpan sAverage = TimeSpan.Zero;
for (int j = 0; j < trials; j++) {
Console.WriteLine("***************************************");
Console.WriteLine("Starting iteration {0}", j.ToString());
st.Start();
for (int i = 0; i < iterations; i++) {
String.Format(info, "Text");
}
st.Stop();
rAverage += st.Elapsed;
Console.WriteLine(st.Elapsed.ToString());
st.Reset();
st.Start();
for (int i = 0; i < iterations; i++) {
String.Format(CultureInfo.CurrentCulture, "Text");
}
st.Stop();
sAverage += st.Elapsed;
Console.WriteLine(st.Elapsed.ToString());
}
Console.WriteLine("***************************************");
Console.WriteLine("Overall Results:");
Console.WriteLine("Using object reference:{0}", TimeSpan.FromMilliseconds(rAverage.TotalMilliseconds / (Double)trials).ToString());
Console.WriteLine("Using static reference:{0}", TimeSpan.FromMilliseconds(sAverage.TotalMilliseconds / (Double)trials).ToString());
Console.ReadLine();
}
}
}
And here are the results:
***************************************
Starting iteration 0
00:00:02.4918791
00:00:02.6975864
***************************************
Starting iteration 1
00:00:05.1777309
00:00:02.7060980
***************************************
Starting iteration 2
00:00:05.1796692
00:00:02.6850936
***************************************
Starting iteration 3
00:00:05.1637124
00:00:02.6671581
***************************************
Starting iteration 4
00:00:05.1498686
00:00:02.7091927
***************************************
Starting iteration 5
00:00:05.2085886
00:00:02.7085847
***************************************
Starting iteration 6
00:00:05.1934733
00:00:02.7077047
***************************************
Starting iteration 7
00:00:05.2302492
00:00:02.7350313
***************************************
Starting iteration 8
00:00:05.2383390
00:00:02.8166922
***************************************
Starting iteration 9
00:00:05.3049657
00:00:02.6893061
***************************************
Starting iteration 10
00:00:05.1531035
00:00:02.6684418
***************************************
Starting iteration 11
00:00:05.1420193
00:00:02.6652652
***************************************
Starting iteration 12
00:00:05.1462953
00:00:02.6682994
***************************************
Starting iteration 13
00:00:05.1606059
00:00:02.7505680
***************************************
Starting iteration 14
00:00:05.4113100
00:00:02.7220753
***************************************
Starting iteration 15
00:00:05.2402528
00:00:02.7108708
***************************************
Starting iteration 16
00:00:05.2144905
00:00:02.7059263
***************************************
Starting iteration 17
00:00:05.1762065
00:00:02.6729379
***************************************
Starting iteration 18
00:00:05.1473431
00:00:02.7072361
***************************************
Starting iteration 19
00:00:05.2706150
00:00:02.8438043
***************************************
Overall Results:
Using object reference:00:00:05.0700000
Using static reference:00:00:02.7120000
I'm not sure how the results from trial 0 end up being different right off hand, I'd have to have a closer look. But it seems that using the static reference is generally faster in this test presuming I've not misused or taken for granted some aspect of the testing code. I'll run my profiler on it and get back with more results.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
The profiler gave different results than the Stopwatch() timing. I think I'd have to agree with the profiler. Who knows what's going on with the the timing in the code to give results like that.
Here's what ANTS says:
Over 200000 iterations total times were
0.556 (sec.) String.Format(info, "Text");
0.638 (sec.) String.Format(CultureInfo.CurrentCulture, "Text");
So they're about the same.
For this version, I changed the reference to the object to point to a new instance
CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.LCID); .
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Thanks carbon_golem,
Could you let me know what do you mean the Profiler please?
regards,
George
|
|
|
|
|
My front end is in asp.net which will call a method from dll which is in C# .In my C# dll i want to call a method from another dll which is in C.In my main page pageload event i call a function foo() from C# DLL which inturns call foobar() from another DLL which is in C. how can i do this ?i really want to know how to give refrence of C dll in C# dll.
Please provide me any usefull link or some small sample code for this.
any help appreciated .
Thanks in advance.
|
|
|
|
|
cristi_alonso wrote: ?i really want to know how to give refrence of C dll in C# dll.
p/invoke
www/pinvoke.net[^] has many examples
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The link you gave is not working .tell me how to do this by PI/invoke?
|
|
|
|
|
i'm creating my very first app, as apparently I have to start refering to myself as a programmer. problem is that i feel like i'm in over my head.
the app im working on need to pass two tables into text files, then from the Form open BeyondCompare to check differences betwixt the tow tables.
my current problem is that of composite formatting.
as i'm passing the tables into text files it would make sence to still make sence of the content within the text files as any discrepacies will need to be investigated.
how do i use composite formatting to space the columns and rows from a DataTable correctly in a text file?
can anyone help please hey
-Klop-
|
|
|
|
|
I have no idea what you're talking about. If you have a datatable, I would expect an Environment.NewLine between lines of text, and that's about it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
never used Environment.NewLine
what i want to achieve is to space the columns in the text files so that it looks like a datatable, this is to make it easy for a person to see where exactly a discrepancy between the two databases is. and report the correct changes to dbadmin
|
|
|
|
|
hi all,
i want to do a login form using workflow in c#,
please help me to design WF at this form....
thanks alot
|
|
|
|
|
There is a workflow forum on codeproject called WPF/WCF/WF. But you need to be more specific if you want help. You can also try the workflow forum at MSDN Forums. Most people at CP seem focused on WPF or WCF.
Kevin
|
|
|
|
|
hi kevin,
are u can give me a small project about it??
thank u...........
|
|
|
|
|
Your best bet is to find the Microsoft Windows Workflow samples on the MSDN site and try and work through one or two of them. Then when you get stuck ask specific questions. It's the only way to learn.
Have a look at the Cutting Edge example here:
http://msdn.microsoft.com/en-us/netframework/aa663322.aspx[^]
The book, Pro WF by Brice Bukovics is very good. However, there may be a new version out soon if it's not already.
Also the MSDN Screencasts on Windows Workflow are quite good.
I'm not using WF at the moment but I did play with it a bit about a year ago.
Kevin
|
|
|
|
|
Hi everybody,
consider the following:
I have a full report that includes a common header/footer and a number of subreports. The subreports can be enabled or disabled with parameters and all show different data sets. Now I want to display the subreport title (or a parameter or textbox value, for that matter) in the parent report header (since subreport headers are not rendered). I couldn't get this to work.
I tried different approaches, including a headline on the subreport set to RepeatWith the table, but it is not repeated. What can I do? It's ok if I have to completely restructure the report. I just don't know how.
Thanks in Advance,
OregonGhost
|
|
|
|
|
I have a class in my windows application named "Category". I have a web service which will be used by the windows application to fill the categories. Inside web service, I have another class say "OnlineCategory", of course this one is serializable. GetCategory() method in the web service returns a "OnlineCategory" instance to the caller (windows application).
I am using this "OnlineCategory" instance and creating a new "Category" instance and binding my controls. But I am looking for a better approach for this. I have the following thoughts
Both "OnlineCategory" and "Category" implements a interface say "ICategory", and all my controls should use "ICategory" for binding. So I can directly bind "OnlineCategory" instance which web service method returns.
Is this a better approach or any other methods available to do this ?
|
|
|
|
|
Hi gurus,
I'd like to know how can I get the decimal separator of the current host?
How can I know if the decimal separator is a point or a coma?
Thanks in advance.
Fred.
There is no spoon.
|
|
|
|
|
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
string decimalSeparator = ci.NumberFormat.CurrencyDecimalSeparator;
Dave
|
|
|
|
|
There's also ...CurrentCulture.NumberFormat.NumberDecimalSeparator
Dave
|
|
|
|
|
If we have a value type, we can force it to be passed by reference using the ref keyword.
Is it possible to do the inverse - pass a reference type by value?
At the moment my class creates a sort of shadow of itself as a struct and passes the struct to acheive this, but I'm sure there's a better way. I looked at cloning but the shallow/deep issues seemed to be more trouble than they were worth!
Dave
|
|
|
|
|
It's easy to get confused by this.
If you try to forcable pass a value type by reference, what is happening behind the scences is the value type is being stuck in a reference type box (refereed to as being 'boxed') and it is a reference to this box that is passed.
With a reference type what you have is actually a pointer (or reference) to the object that is stored in the heap. By default you pass that pointer _by value_. You are already passing a pointer to a reference type by value.
(If you add the ref keyword, you will be then passing a pointer to a reference type by reference. Therefore you end up passing a reference to a reference.)
It isn't possible to pass a reference type by value because the object only exists on the heap. If you create a struct the struct will only contain a pointer to the reference type on the heap, so passing the struct by value will still provide the same pointer to the same object on the heap.
The only way to really achive this effect is to do some form of deep copy the object and pass that instead.
Why do you want to pass a reference type by value?
Simon
|
|
|
|
|
Simon Stevens wrote: If you try to forcable pass a value type by reference, what is happening behind the scences is the value type is being stuck in a reference type box (refereed to as being 'boxed') and it is a reference to this box that is passed.
No, passing a value type by reference doesn't use boxing. If it would, the method would change the boxed copy instead of the original.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Good point, my mistake. it passes a pointer to the original value type (which I'm assuming is on the in the stack frame of the original method).
Simon
|
|
|
|
|
Yes, if the variable is a local variable in a method, it's in the stack frame.
If it's a member variable in an object, it has to send a reference instead. Or perhaps fix the object to keep the GC from moving it, so that it can send a pointer to the member.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|