What does the %= operator do? [duplicate]

From MSDN: The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators. So in your case, the following string is the same as this one: Which also applies to all operators: a += b equals to a = a + ba /= b equals to a = a / … Read more

Categories c# Tags

Proper way to initialize a C# dictionary with values

I can’t reproduce this issue in a simple .NET 4.0 console application: Can you try to reproduce it in a simple Console application and go from there? It seems likely that you’re targeting .NET 2.0 (which doesn’t support it) or client profile framework, rather than a version of .NET that supports initialization syntax.

Deserialize JSON with C#

You need to create a structure like this: Then you should be able to do: The names of my classes are just an example. You should use proper names. Adding a sample test: Produces:

How to use Global Variables in C#?

In C# you cannot define true global variables (in the sense that they don’t belong to any class). This being said, the simplest approach that I know to mimic this feature consists in using a static class, as follows: You can then retrieve the defined values anywhere in your code (provided it’s part of the same namespace): In order … Read more

Checking if an object is null in C#

It’s not data that is null, but dataList. You need to create one with Even better: since it’s a field, make it private. And if there’s nothing preventing you, make it also readonly. Just good practice. Aside The correct way to check for nullity is if(data != null). This kind of check is ubiquitous for reference types; even Nullable<T> overrides the equality operator to … Read more

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