Root element is missing

Hi this is odd way but try it once Read the file content into a string print the string and check whether you are getting proper XML or not you can use XMLDocument.LoadXML(xmlstring) I try with your code and same XML without adding any XML declaration it works for me As stated by Phil in below … Read more

How to catch all exceptions in c# using try and catch?

Both approaches will catch all exceptions. There is no significant difference between your two code examples except that the first will generate a compiler warning because ex is declared but not used. But note that some exceptions are special and will be rethrown automatically. ThreadAbortException is a special exception that can be caught, but it will automatically be … Read more

Case insensitive ‘Contains(string)’

To test if the string paragraph contains the string word (thanks @QuarterMeister) Where culture is the instance of CultureInfo describing the language that the text is written in. This solution is transparent about the definition of case-insensitivity, which is language dependent. For example, the English language uses the characters I and i for the upper and lower case versions of the ninth letter, whereas the Turkish language uses … Read more

Does Java have something like C#’s ref and out keywords?

No, Java doesn’t have something like C#’s ref and out keywords for passing by reference. You can only pass by value in Java. Even references are passed by value. See Jon Skeet‘s page about parameter passing in Java for more details. To do something similar to ref or out you would have to wrap your parameters inside another object and pass that object reference in as … Read more

Make first letter of a string upper case (with maximum performance)

Solution in different C# versions C# 8 with at least .NET Core 3.0 or .NET Standard 2.1 Since .NET Core 3.0 / .NET Standard 2.1 String.Concat() supports ReadonlySpan<char> which saves one allocation if we use .AsSpan(1) instead of .Substring(1). C# 8 C# 7 Really old answers This version is shorter. For a faster solution, take a look at Diego’s answer. Probably the fastest … Read more

How to use WPF Background Worker

Add using Declare Background Worker: Subscribe to events: Implement two methods: Run worker async whenever your need. Track progress (optional, but often useful)a) subscribe to ProgressChanged event and use ReportProgress(Int32) in DoWorkb) set worker.WorkerReportsProgress = true; (credits to @zagy)

How to block until an event is fired in c#

If the current method is async then you can use TaskCompletionSource. Create a field that the event handler and the current method can access. This example uses a form that has a textblock named WelcomeTitle and two buttons. When the first button is clicked it starts the click event but stops at the await line. … Read more