You searched for how does c# work. We found 81 results in 0.162 seconds.

How to use bitwise NOT operator with shift operator in C#?

I don't understand how this expression works. ~(1 << 1) = -3 What I do understand is that 1 << 1 has a value of 10 in binary and 2 in base 10. How did it get a -3...
Jon Skeet
people
quotationmark

The bitwise inverse operator is entirely separate from the shift here. You've started with input of 10 (binary) - which has a full 32-bit representation of 00000000_00000000_00000000_00000010 The bitwise inverse is... more

people

the type name text does not exist in the type xmlnodetype

I am trying to read a certain section from an xml file in C#. I tried using this code here but I get a compiler error under the Text in XmlNodeType.Text but the weird thing is it...
Jon Skeet
people
quotationmark

XmlNodeType is an enum. XmlNodeType.Text is a value, not a type, but you're trying to use it as the type of the aa variable. Furthermore ReaderInnerXml() returns a string, so it's not clear how you expect to iterate over it. Do you have... more

people

Does a MemoryBarrier guarantee memory visibility for all memory?

If I understand correctly, in C#, a lock block guarantees exclusive access to a set of instructions, but it also guarantees that any reads from memory reflect the latest version...
Jon Skeet
people
quotationmark

Reads within the lock block see the latest versions of a variable and writes within the lock block are visible to all threads. No, that's definitely a harmful oversimplification. When you enter the lock statement, there a memory... more

people

How do I check if a value is assigned to an int in c#?

int x might not have an assignment. How do I detect that? What value does int hold when it is unassigned? This gives me a warning in Visual Studio: public SomeMethod(int x) { ...
Jon Skeet
people
quotationmark

int x might not have an assignment. That's simply not true. In your case, x is a parameter - it's "definitely assigned" from the start of the method, in specification terminology. When someone calls the method, they have to provide a... more

people

How to use string as variable name in c#

am having a viewstate which pertains value like: string temp; ViewState["temp"] = dc.ColumnName.ToString(); This returns weekdays like: Monday,tuesday,wednesday etc Now am...
Jon Skeet
people
quotationmark

No, you can't. At least not without reflection, and you shouldn't be using reflection here. Variables in C# are a compile-time concept. (Even with reflection, it'll only work for fields, not for local variables.) If you want a collection... more

people

ReadAllText does only return first line

I'm trying to replicate this PHP function with VB.net: function getGiantsModMD5Hash($modFile) { $info = pathinfo($modFile); // Add mod zip data $fileContent =...
Jon Skeet
people
quotationmark

A zip file is not a text file, so don't try to use it as if it were. It's vitally important that you distinguish between text data and binary data - not just here, but all over the place. Hashing a file is simple though. Unfortunately as... more

people

Why does << 32 not result in 0 in javascript?

This is false: (0xffffffff << 31 << 1) === (0xffffffff << 32) It seems like it should be true. Adding >>> 0 anywhere does not change this. Why is...
Jon Skeet
people
quotationmark

The shift operators always effectively has a right operand in the range 0-31. From the Mozilla docs: Shift operators convert their operands to 32-bit integers in big-endian order and return a result of the same type as the left... more

people

How to use C# LINQ Union to get the Union of Custom list1 with list2

I am using the Enumerable.Union<TSource> method to get the union of the Custom List1 with the Custom List2. But somehow it does not work as it should in my case. I am...
Jon Skeet
people
quotationmark

The oddity here is that your class implement IEqualityComparer<CustomClass> instead of IEquatable<CustomClass>. You could pass in another instance of CustomClass which would be used as the comparer, but it would be more... more

people

does Array.sort (or any collections sort method) depends on size of an individual items in C#?

As we all know the sort method the array works upon. The speed is affected by the number of items stored in an array. However would the speed be affected by the size of the...
Jon Skeet
people
quotationmark

Would the speed of sorting differ with 100 string items which are all 30 string characters? Potentially, yes. Potentially, no. It depends. If you have a bunch of strings which only differ at character 30, that will take longer to sort... more

people

How to make a case insensitive list search in C#?

I've been trying to make a list search method where I could present the items in the list unaffected and after a week going through every search method I could find I realizes...
Jon Skeet
people
quotationmark

You could use IndexOf with a case-insensitive comparison: var query = posts.Where( logg => logg.IndexOf(searchKey, StringComparison.CurrentCultureIgnoreCase) != -1); foreach (string result in query) { ... more

people