« first day (2220 days earlier)   

12:46 AM
@hilli_micha you can go Foreach(var item in list) even if there are no item, it will not throw an exception but you should check if list is not null and in some cases if list is binded UI and collection gets modified when you itereting it in foreach it will throw and exception so you should check to null and to List.ToList() and iterate
 
 
2 hours later…
3:00 AM
I'm still learning about tasks, so I put this up for code review, if anyone is bored I'd appreciate any tips codereview.stackexchange.com/questions/146810/…
 
 
5 hours later…
7:45 AM
Good morning.
 
8:12 AM
morning
how to export datagridview to pdf with some text above the table?
 
8:30 AM
look mate I googled and its the first result
and it looks like its correct
please don't tell me you want datagridview to support printing to pdf out of the box
 
 
2 hours later…
10:26 AM
@QPaysTaxes good question, I'm afraid I don't know
 
Hi
I have string query(script) for example "Create Table Test()" and I want to run this query every time when the App is launched and query size is different.
I researched and found some think like
System.Text.ASCIIEncoding.Unicode.GetByteCount(string);
System.Text.ASCIIEncoding.ASCII.GetByteCount(string);
 
what type of app?
 
it is returning the size
 
why would you create the same table every time? (hint: it'll only work the first time)
 
but when the query is changes like replacing the letter it is the same size
but the query completely different than before
 
10:36 AM
@Jamaxack It looks like you're trying to replicate logic that libraries like EF do - doing DB diff operations
 
this is test app and when you run app it should create database based on model
 
EF can tell if your model is out of sync with your tables.
 
We are using our own code generator
if model got changed so script is size or some thing is different than before so it should create database
 
So you have both versions of the script, the current one and the previous one?
 
it is usually very long script
so I'm thinking to save only size or some think
that way I can compare it
 
10:39 AM
@Jamaxack Is this a real issue with performance you need to solve, or does it just seem like a good idea?
Unless it's a multi-MB scripts, running a simple diff between the two files might be quite enough.
 
if I save the byte counts and if the script was "Testa" and it is got change to "Taste" it gives me the same byte size
 
@Jamaxack Length is a terrible measure for equality.
 
@AvnerShahar-Kashtan Yeah, You're right
Yeah it is performance issue, I don't want to create every time data base unless there model got changed
 
@Jamaxack Sure, but is running a char-by-char diff a performance problem?
 
@AvnerShahar-Kashtan char-by-char? can you explain me please?
 
10:43 AM
You can call GetHashCode() on the strings to compare them.
 
you mean save all query and compare with new one?
 
@Jamaxack There are all sorts of diff algorithms that can check if two texts are identical and if not, give you the difference between them:
9
Q: C# Diff Algorithm for Text

MollyI'm looking for a diff algorithm that will produce results like SO's edit revisions page. I've more or less just started looking and I'm not opposed to doing it myself but I don't need to reinvent the wheel. I'll be using C# 4.0. I'll basically have two strings, and old one and a new one. I...

Alternately, if you just want to know if two strings are identical or not, you can call GetHashCode() on both and compare them.
Two identical strings should have identical hashcodes in the standard C# runtimes I know.
 
GetHashCode() is think that I need
@AvnerShahar-Kashtan thanks a lot
 
Remember that hashcodes aren't a universal identifier. The same string might have a different hashcode if the same method is run at a different time, on a different .NET version, etc.
Compare the two hashcodes calculated by the same code, don't store a hashcode somewhere for later comparison
> The hash code itself is not guaranteed to be stable. Hash codes for identical strings can differ across versions of the .NET Framework and across platforms (such as 32-bit and 64-bit) for a single version of the .NET Framework. In some cases, they can even differ by application domain.
 
I wonder if there is a syntax tree library you could use to determine whether the script is semantically different
 
10:49 AM
@TomW There are a couple I know, but commercial.
 
hrrm...Roslyn analyzer?
 
does Roslyn support SQL? maybe the AST it builds to support refactorings would do the trick. If it supports parsing SQL to start with anyway
 
Dunno. I think SQL syntax can be tricky.
With arbitrary aliases possible for tables, arbitrary column names for calculated columns, etc.
 
 
3 hours later…
1:32 PM
In WinForms, does Form.Close() immediate stop the execution of any code in that form? For example, if I wanna close one form before opening another from a click handler, can I just do this.Close(); new NextForm().Show();?
 
It should work. Remember that a method is a method, regardless of whether it's a click handler or not. To prevent the new NextForm().Show() from running, it would have to end the method execution, for example by throwing an exception.
However, note that what you're doing is instantiating a new object inside a method, then letting that method end. Effectively, you don't have any variable pointing to that form anymore.
 
And that error could be thrown if this.Close() tells the GC to immediately dispose of the Form
 
@QPaysTaxes It is unlikely to do that - the GC is usually left to decide by itself when to react - and it's possible that a call to Show() registers the newly created form in some global dictionary somewhere so that it isn't disposed. But it's hard to be sure.
A more common approach for wizard-style navigation isn't to have each form instantiate the next one and go out of scope, but to have one orchestration view that manages the navigation between them.
 
This is different forms, though, not just different pages in the same one
And I'd be shocked if C# let an object get GC'd if it was a still-visible form
 
What use case is this for? A Login form that, after successfully logging in, launches the main UI?
That's the only common use case I can think of.
 
1:37 PM
Er, sorta
I've got a homework assignment to design and build the UI from Hell
This is an interstitial "loading" form
 
Not interactive, just a splash screen?
 
Basically
But it's connecting two separate things
 
2:01 PM
You know what I would like? The ability to skip an item in a Select statement.
 
??
Oh, right, Select doesn't select things from the list, it applies a mapping
 
C#'s naming for LINQ is dumb.
 
So you need to filter after the select (or before).
8
A: What is the reasoning behind naming of the .NETs Select (Map) and Aggregate (Reduce)?

svickLINQ methods in .Net source.Where(x => condition) .Select(x => projection) were named to be consistent with LINQ query syntax in C# (and VB.NET) from x in source where condition select projection which was designed to be familiar to people who know SQL SELECT projection FROM source...

 
Before, probably
I know the reasoning
But stupid decisions also have reasons
 
2:05 PM
*shrug*.
They're names, and relatively easy once you understand their purpose.
Select makes more sense than map or project when dealing with LINQ to SQL or LINQ to Entities. It maps directly to the domain.
 
At the same time, Map is the standard terminology (in math, upon which basically everything in CS is based) and doesn't make the average person think of an action totally unrelated to what it actually does
 
Map doesn't mean anything to the average person either. It makes sense only if you already know what it does, in which case, you already know what it does.
 
...I'm not saying Map means something. I'm saying Select means the wrong thing.
 
And "standard terminology" is context-dependent. LINQ isn't math. It isn't CS either.
 
True
 
2:10 PM
Since I use LINQ to objects to manipulate lists and collections more than I do to manipulate DBs, I would also prefer Map to Select, but it doesn't really bother me.
 
...?
 
(forgot the but. Added it later. :))
 
Oh
It's funny how easy it is to trip up a brain that hasn't slept in over a day
 
I also stayed up till 3:00am last night over a toothache. :(
 
Oof
I've just got homework to do
 
 
3 hours later…
5:28 PM
Is there a way to get a unique ID for an object I can use when logging to track an item in a multithreaded environment?
I'm currently using GetHashCode which seems to work fine. But I was curious if there was a better alternative.
 

« first day (2220 days earlier)