How do I update the GUI from another thread?

The simplest way is an anonymous method passed into Label.Invoke: // Running on the worker thread string newText = “abc”; form.Label.Invoke((MethodInvoker)delegate { // Running on the UI thread form.Label.Text = newText; }); // Back on the worker thread Notice that Invoke blocks execution until it completes–this is synchronous code. The question doesn’t ask about asynchronous … Read more

How do you convert a byte array to a hexadecimal string, and vice versa?

You can use Convert.ToHexString starting with .NET 5. There’s also a method for the reverse operation: Convert.FromHexString. For older versions of .NET you can either use: public static string ByteArrayToString(byte[] ba) { StringBuilder hex = new StringBuilder(ba.Length * 2); foreach (byte b in ba) hex.AppendFormat(“{0:x2}”, b); return hex.ToString(); } or: public static string ByteArrayToString(byte[] ba) … Read more

Why not inherit from List?

There are some good answers here. I would add to them the following points. What is the correct C# way of representing a data structure, which, “logically” (that is to say, “to the human mind”) is just a list of things with a few bells and whistles? Ask any ten non-computer-programmer people who are familiar … Read more

What does the [Flags] Enum Attribute mean in C#?

The [Flags] attribute should be used whenever the enumerable represents a collection of possible values, rather than a single value. Such collections are often used with bitwise operators, for example: var allowedColors = MyColor.Red | MyColor.Green | MyColor.Blue; Note that the [Flags] attribute doesn’t enable this by itself – all it does is allow a … Read more

How to loop through all enum values in C#? [duplicate]

Yes you can use the ‍GetValue‍‍‍s method: var values = Enum.GetValues(typeof(Foos)); Or the typed version: var values = Enum.GetValues(typeof(Foos)).Cast<Foos>(); I long ago added a helper function to my private library for just such an occasion: public static class EnumUtil { public static IEnumerable<T> GetValues<T>() { return Enum.GetValues(typeof(T)).Cast<T>(); } } Usage: var values = EnumUtil.GetValues<Foos>();

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