When should I use Lazy?

You typically use it when you want to instantiate something the first time its actually used. This delays the cost of creating it till if/when it’s needed instead of always incurring the cost. Usually this is preferable when the object may or may not be used and the cost of constructing it is non-trivial.

WPF global exception handler [duplicate]

You can trap unhandled exceptions at different levels: AppDomain.CurrentDomain.UnhandledException From all threads in the AppDomain. Dispatcher.UnhandledException From a single specific UI dispatcher thread. Application.Current.DispatcherUnhandledException From the main UI dispatcher thread in your WPF application. TaskScheduler.UnobservedTaskException from within each AppDomain that uses a task scheduler for asynchronous operations. You should consider what level you need to … Read more

What Are Some Good .NET Profilers?

I have used JetBrains dotTrace and Redgate ANTS extensively. They are fairly similar in features and price. They both offer useful performance profiling and quite basic memory profiling. dotTrace integrates with Resharper, which is really convenient, as you can profile the performance of a unit test with one click from the IDE. However, dotTrace often … Read more

Why do we need boxing and unboxing in C#?

Why To have a unified type system and allow value types to have a completely different representation of their underlying data from the way that reference types represent their underlying data (e.g., an int is just a bucket of thirty-two bits which is completely different than a reference type). Think of it like this. You … Read more

Set object property using reflection

Yes, you can use Type.InvokeMember(): using System.Reflection; MyObject obj = new MyObject(); obj.GetType().InvokeMember(“Name”, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty, Type.DefaultBinder, obj, “Value”); This will throw an exception if obj doesn’t have a property called Name, or it can’t be set. Another approach is to get the metadata for the property, and then set it. This will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)