|
For a string, a == b is always a value comparison, but ... it starts with a reference comparison!
1) operator == calls string.Equals.
2) The first thing that Equals does is this:
if ((Object)a==(Object)b) return true;
Which is a reference comparison, as you'd expect. A good percentage of the time, this will make the process faster.
3) It then checks for null in either side, and returns false if either is null.
4) It then compares the lengths - any difference is a return false.
5) It then calls another method which repeats those two tests (if it's the debug build) and throws an exception via Contract.Requires
6) It then uses unsafe code with pointers to do a value comparison (but quickly, using 12 bytes at a time for AMD processors, and 10 for Intel - don't ask)
So technically, "a == b" is a value comparison, but it has a few additional tests to speed things up, including a reference comparison.
But you really aren't supposed to know that, the traditional answer is "value comparison for strings". It may be that they wanted you to expand on "value type" and maybe explain why it's not a reference comparison?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wow, my reply in the interview would have been "I don't know, nor do I care". It must be a specialised requirement if this depth of knowledge is required for the position (I do LOB apps only).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You should probably care about the value type comparison that is specific to strings - it does affect performance after all. And knowing that release optimisation could change how things work could be important.
But interning strings - particularly at run time - you don't normally need to know about. (The compile time interning is pretty much irrelevant as it's a "side effect" of immutability.)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Dear All,
I have an unmanaged DLL developed by Delphi language and it's support 86x and 64x and I want to use the DLL in my c# windows form application which use any cpu as a platform target but this error occurred
"System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at ScaleDLL.frmMain.AclasSDK_Initialize(Pointer Adjuct)
at ScaleDLL.frmMain.frmMain_Load(Object sender, EventArgs e) in F:\Dot Net Projects\Dlls\ScaleDLL\ScaleDLL\frmMain.cs:line 147"
and we can't change the platform target to 86x because we use other libraries and it is not work when change the platform and we need to use this dll on the AnyCpU platform.
Please help me ASAP.
Thank You
|
|
|
|
|
It's not simple, not at all.
Because you are using 64 bit libraries already, you can't access 32 bit libraries on the same process - even if you compile for "any cpu" that doesn't mean that a process can "switch" dynamically between the two.
If you want to cleanly use your legacy DLL, you will need to either convert everything else to x86, convert the legacy DLL to 64 bit, or ... start reading: Accessing 32-bit DLLs from 64-bit code | Reflections on IT[^] Do not expect this to be a clean, neat, and easy solution.
And no, I've never needed to do it - so I can't help you here...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Hi!how to create wordsearch in c#?
|
|
|
|
|
With classes, some variables, methods and a whole host of semi-colons. Hopefully you'll throw some algorithms in there as well.
This space for rent
|
|
|
|
|
|
|
|
 Your answer is contained in the text below:
bxIpOAZvrvLsWNTKAecZLbZZHkmgjiEuZxaHyGwzfSTrtdAHFRBBIoFqvncYZnJMQbxFaCJmIulOTsQU
WDmQMnhsEBqnmIEvfYVqFBirsSJhHIYYRkqNajTeWDAxVKkuxSPbHiaHHyrOWjdlFjQhmBRdfnjqaEPd
FXgEJBraarSxWmaYuJPBaRCgDszOoKfDfCQvvPJmehLfTCCjcwzOPopWQiqMxWKnhEdxEBrLdOFNJMsp
thwrEmkUNpuwsYaJPOfgVpxbBcuStoSVcdkLegIBSsFdbZkuFsdpwvlGttRXAagoPQvMjaMFhvKkwXex
WYhUEedrZTdKlzIIWqWgLDMKLOnVwaawcOShcnlUwfbZXyFiwxqcfFrtVVczjPaFQYpnMBLYVUIPDCuu
ZXzobkLrcUkvxfVPUJfYquzekEtlSqEOZcwSlVRqNObDSaxOuwhdXJBCZaIJTUYYIPUFtBtEnpzEeQcv
YAzyggmIFcVClIdihsZeKxILMTZUbWmOFJzrdCkDluFPQccHitPbrZzBHYpPDeAKafWUKWFJZUZkanPo
CcPuxsMGRxhVygHwChSEZBmPcYyLKOpeARvmgskmAdSSIqYMdXtkfrXqUfSSVPZqRGTvaXliyafAnyfO
IHgIzcEzPMbrOoONEJzimEqAVThdmvoubDTeGvOrEbUUBVwTKbhUfWIBJtGvNfghojXdydixZlWRe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OpGXEmqdmQFLVHUzwRxyTtIh
hhKXodSTKEWLdbfOvVFuirWsGFZgfMdqPtvIwmeDwWLYWVuIktUJiQWuNMZpvJAvkiqtbShdITxYDOrr
xqKexxQkkAgwVmbLMrfWLYtuzOkrjAFMxbREyqHzrNvtCDHgNKWzHFSjgtfDrOCVamABgDbVZslVDLuj
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Step 1: follow the question/answer guidelines of the forum (first 2 posts of each forum)
For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside < p r e > < / p r e > tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
|
|
|
|
|
I've read that it's not a good idea to fire an sync method from a property, yet I see plenty of places where I would want to do this.
For example, at the top of my Contacts view I have a Search field bound to a ContactSearchValue string property. When the user enters a seaarch value I reload all the contacts that match.
To do this I call LoadContacts from the settter of the property. Because LoadContacts is async I get a compilation warning saying "Because this call is not awaited, execution of the current method continues before the call is completed" This is OK beause it in a property settings and there's no other code.
Anyone have any thoughts on this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It is not a good idea because it is fire-and-forget. Unit-testing this kind of code is a pain or plainly not possible.
But yes you can do it... Just be aware of the bad stuff that may happen.
|
|
|
|
|
How else would you reload the contacts when a search value is entered?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It is mostly done in the SearchCommand... Which is triggered if the user hits the enter key or if a small amount of grace period has passed.
|
|
|
|
|
That seems like a lot of work - hook up a command to a property to fire a method??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It just sound like a lot of work, but it isnt.
If you have fire and forget async methods in the property, you can't control what they are doing. You don't know if there are started or finished or whatever... If you have somewhere code that depends on the result of your fire and forget code, then you will looking for bugs that you will never find.
If your fire and forget code is just updating visual stuff (like icons or colors...) then well go for it... If other logic depends on it... Don't do it. Well actually you can do it, if you a fan of bugs. Debugging is a fun hobby. More fun if you are debugging asyncronous code.
On top of that... Fire and forget code is very hard (most of the time impossible) to unit test.
|
|
|
|
|
Kevin Marois wrote: I've read that it's not a good idea to fire an sync method from a property
Did you mean "async method", not "sync"?
|
|
|
|
|
Yes
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Any searching I do, usually incrementally on a separate thread, gets invoked from the "text changed" event of the target textbox. Keyed input get queued or discarded depending on what the "search" is doing at any given time. The search might involve a web service (e.g. postal addresses).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi everybody,
I have implemented a Icommand RowHeaderToggleButton in my MVVM application type.
My problem: whenever I click on the toggle button, nothing happens.
Could someone help me with this issue?
Best regards,
Hervend
xaml:
<datagrid.rowheadertemplate>
<datatemplate>
<togglebutton x:name="RowHeaderToggleButton" cursor="Hand"
="" command="{Binding RowHeaderToggleButtonCommand}">
c# (inside view model):
public AlarmsListViewModel(DataBase dataBase)
{
this.dataBase = dataBase;
this.alarms = new ObservableCollection<alarmviewmodel>();
foreach (Alarm alarm in this.dataBase.Alarms)
{
this.alarms.Add(new AlarmViewModel(alarm));
}
this.ListOfAlarms = CollectionViewSource.GetDefaultView(this.alarms);
if (this.ListOfAlarms == null)
throw new NullReferenceException("ListOfAlarms");
this.ListOfAlarms.CurrentChanged += new EventHandler(this.OnCollectionViewCurrentChanged);
}
#region Fields
private readonly DataBase dataBase;
private readonly ObservableCollection<alarmviewmodel> alarms;
private readonly ICollectionView ListOfAlarms;
private ICommand rowHeaderToggleButton;
#endregion //Fields
...
public ICommand RowHeaderToggleButtonCommand
{
get
{
if (this.rowHeaderToggleButton == null)
this.rowHeaderToggleButton = new RelayCommand(() => this.RowHeaderToggleButton_Click(), () => this.CanToggle());
return this.rowHeaderToggleButton;
}
}
private bool CanToggle()
{
return true;
}
private void RowHeaderToggleButton_Click()
{
DataGridRow row = this.ListOfAlarms.CurrentItem as DataGridRow;
if (row.DetailsVisibility == Visibility.Visible)
row.IsSelected = false;
else
row.IsSelected = true;
}
|
|
|
|
|
Where do you bind the DataTemplate to the class? I.e something like:
<DataTemplate DataType="{x:Type local:AlarmsListViewModel}">
|
|
|
|
|
Hi Kenneth,
Thank you for your reply. Actually for me the DataTemplate concept seems a little bit hard to handle when dealing with some types of objects. And, in this specific case, a simple toggle button in the MVVM approach.
The range of the DataTemplate is limited to the toggle buttons associated to the rows of the DataGrid. that's the reason why I didn't have added extra arguments to it. But as I already stated, I'm still struggling to understand the way of correctly applying the DataTemplating.
|
|
|
|