|
|
You could start by NOT SHOUTING AT US.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Sorry for that, my native language is not english, so my writing could look a bit rude
|
|
|
|
|
With thanks to Pete O'Hanlon and OriginalGriff:
You can use this method to center a control in its parent control:
private void CenterControl(Control control)
{
control.Left = (control.Parent.ClientRectangle.Width - control.Width) / 2;
control.Top = (control.Parent.ClientRectangle.Height - control.Height) / 2;
}
example use:
CenterControl(pictureBox1);
|
|
|
|
|
I will test it on my project, my thanks to you and Pete O'Hanlon and OriginalGriff
|
|
|
|
|
New to C#,
The plan:
1. Parse a log file of over 250,000 records daily.
2. Storage the outcome of the file parsing somewhere (file, Array, DB, other), the average # of records is about 20,000.
3. Use a DataGrid to bind the result of the parsing and present to user.
I will like some suggestion on #2 (Pros/Cont, performance, etc.), the temporary storage to be bind to the Datagrid. Keep in mind the number of records could be 25K or more.
Thanks in advance.
|
|
|
|
|
I'd probably use a DataTable - they are designed for exactly that - or a List of a custom class.
But I wouldn't present 25,000 rows of anything directly to a user: that's just silly. Page it, filter it, search it: but just showing him the data and letting him pick the bones out is a recipe for unhappy users...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What kind of datagrid? If in WinForms, I'd recommend virtualizing the DGV.
Why should the user look at 20k worth of data? For validation? How about only showing the stuff where there were import-errors? It's not like anyone is going to read a few pages worth of phone-book material, they'll simply click "accept"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I've been using Basic since the beginning and VB since version 1. At an advanced age I am learning c#.
Is there a good site which explains the big picture?
I mean things like classes, methods, components, resources, how it all fits together.
I know how to write Hello World, I've written a few apps now but keep bumping into my own ignorance.
Most sites seem to start off too simple and then jump in the deep end.
Any help appreciated.
|
|
|
|
|
Generally, I'd say ignore websites - and particularly ignore Youtube tutorials - and get yourself a book (or better a course).
Both tend to be a lot better structured, introducing each subject in a streamlined way rather than dropping you in the deep end while covering all the material - a course is better because if you don't understand something you can talk to the tutor and he can explain it in different ways until you do.
Wrox, Addison Wesley, and Microsoft Press do some good ones - just start at the beginning and work your way through doing all the exercises. All of them should explain classes, methods, evente, and so on and why they are used.
But if you are proficient in VB versions above VB6, then the transition to C# shouldn't be too complicated: they both use the same .NET framework which you should be familiar with, and that means the learning curve is vastly reduced. And VB uses classes, methods, events - it's just the syntax which is rather better in C#!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you, much appreciated.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
.NET Book Zero[^] is a great starting point, especially if you have some programming knowledge.
|
|
|
|
|
|
just tell me when we compare two string by == operation then does it compare by value or ref?
i read it https://stackoverflow.com/a/3678923
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/how-to-test-for-reference-equality-identity
but not very clear.
how to compare by ref and by value ?
i heard string intern. say if we have two string variable having same data then one string object is created and two string variable point to same memory address.
string strA = "Hello world!";
string strB = "Hello world!";
Console.WriteLine("ReferenceEquals(strA, strB) = {0}",
Object.ReferenceEquals(strA, strB));
when we check like this below way
if(strA==strB) then the comparision happen by value or by ref?
please guide me right info. thanks
|
|
|
|
|
Strings are reference types, but string comparisons are made as value types:
string a = "Hello World";
string b = "Hello";
string c = " World";
string d = b + c;
Console.WriteLine("{0}:{1}:{2}:{3}", a == d, a.Equals(d), (object)a == (object) d, object.ReferenceEquals(a, d));
Will give you:
True:True:False:False Because the first two tests use the string specific comparison, and the other two specifically do reference comparisons.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
With strings, there is another fact to consider. When the compiler can detect that they have the same value, the compiler will make sure that they have the same reference also. It can do that optimization because strings are immutable.
In the example given by OriginalGriff, the compiler did not detect that and thus the compiler created two different references.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
That's where it gets complicated (and why I didn't mention it - he is a beginner, after all).
The compiler can detect and intern strings, but the runtime doesn't unless you specifically ask it to:
string a = "Hello World";
string b = "Hello";
string c = " World";
string d = b + c;
Console.WriteLine("{0}:{1}:{2}:{3}", a == d, a.Equals(d), (object)a == (object)d, object.ReferenceEquals(a, d));
d = string.Intern(d);
Console.WriteLine("{0}:{1}:{2}:{3}", a == d, a.Equals(d), (object)a == (object)d, object.ReferenceEquals(a, d));
Will give you:
True:True:False:False
True:True:True:True As the "new" string is now in the Intern pool.
However ... in the release version of my original code you will probably get different results, as the optimiser will likely compact that code and intern the strings anyway!
There is a good description of the intern pool here: Understanding C#: String.Intern makes strings interesting - O'Reilly Broadcast[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i have a very small question sir.
string a = "Hello World";
string b = "Hello World";
when we compare like if(a==b) then what will happen?
== operator compare by value or reference ?
when two string variable having same value and if == operator compare by vale then why value is checked by reference ?
please help me to understand this small area. thanks a lot in advance sir.
|
|
|
|
|
At this stage, I'd say "don't worry about it" - because it starts to get pretty complicated. When you write code like that, two additional factors come into play: optimisation and interning.
Optimisation is not normally applied to debug builds - they are optimised for "debuggability" not performance and that means that large sections of the compiler do not get used that can make significant changes to your code. For example, the compiler can look at this:
public bool IsSame()
{
string a = "Hello World";
string b = "Hello World";
return a == b;
} And "know" that it will always produce the same result: true. So the compiler can "throw away" the whole method and replace it with inline code for "true" wherever your code references it.
That makes it very difficult to say "it's this type of comparison" because the comparison may never occur at all, depending on what happens in the surrounding code! It doesn't do that for debug builds, because it makes it a lot harder for you the developer to work with in the debugger - you can't set a breakpoint on code which has been optimised out!
Interning is another complexity, and one I was hoping to avoid - and why I wrote my original code exactly the way I did. Interning basically means that because strings are immutable, the compiler "knows" that the two string literals are the same, so it only ever keeps one copy of it. So the comparison changes: it becomes a comparison between two identical references, so the question of "value or reference comparison?" becomes moot: they are the same. To see what I mean, try modifying my original code:
string a = "Hello World";
string b = "Hello";
string c = " World";
string d = b + c;
string e = "Hello World";
Console.WriteLine("{0}:{1}:{2}:{3}", a == d, a.Equals(d), (object)a == (object)d, object.ReferenceEquals(a, d));
Console.WriteLine("{0}:{1}:{2}:{3}", a == e, a.Equals(e), (object)a == (object)e, object.ReferenceEquals(a, e)); Run that, and you will get different results for the two WriteLines:
True:True:False:False
True:True:True:True The strings have been interned, so the references are the same.
If you want to know more - and this stuff can get quite complicated - I'd point you are the same link I did Bernhard: Understanding C#: String.Intern makes strings interesting - O'Reilly Broadcast[^] - but to be honest, this isn't stuff you need to know 99% of the time as it makes absolutely no different to how you code your app!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Sir i was asked in interview that if we execute this code a==b then will it be compare by value or reference ? i said value and they told me nothing. i guess i was wrong.
so tell me when we compare a==b does this comparison occur by value or ref if two string variable having same data. thanks
|
|
|
|
|
If both variables are declared as string , then it compares by value.
Determines whether two specified strings have the same value.
public static bool operator == (String a, String b) {
return String.Equals(a, b);
}
public static bool Equals(String a, String b) {
if ((Object)a==(Object)b) {
return true;
}
if ((Object)a==null || (Object)b==null) {
return false;
}
if (a.Length != b.Length)
return false;
return EqualsHelper(a, b);
}
(Where EqualsHelper[^] essentially compares the strings character by character, but using unsafe code to improve the performance.)
If either variable is declared as object , then it will compare by reference.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
it seems to me that if check two string variable
String.Equals(a, b); OR a == b then it will be checking by value but if i check this way
if ((Object)a==(Object)b) then this type of checking is done by reference.
do i understand properly now ? am i right now ?
|
|
|
|
|
Yes, that's correct.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thanks you sir for your great help.
|
|
|
|
|