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

Why does short circuit evaluation work when operator precedence says it shouldn't?

In JavaScript and Java, the equals operator (== or ===) has a higher precedence than the OR operator (||). Yet both languages (JS, Java) support short-circuiting in if...
Jon Skeet
people
quotationmark

Or am I confusing matters? You are. I think it's much simpler to think about precedence as grouping than ordering. It affects the order of evaluation, but only because it changes the grouping. I don't know about Javascript for sure,... more

people

Why does my switch work when it has single quotes?

So disclaimer, I am pretty new to C# and trying to learn the finer intricacies. I have a classwork assignment that I coded and it works, but I'm not sure why it works, and want to...
Jon Skeet
people
quotationmark

There's an implicit conversion from char to int, and a constant char expression can be used as a constant int expression, which is what you've got. The value of the int is the UTF-16 code unit associated with the char. Here's another... more

people

Why does the "as" operator not use an implicit conversion operator in C#?

I have defined implicit string conversion from/to a certain type in C# (dummy code): public class MyType { public string Value { get; set; } public static implicit...
Jon Skeet
people
quotationmark

Why does the soft cast not use the implicit converter? Well, that's the way the language is specified, basically. From the C# 5 specification section 7.10.11: If the compile-time type of E is not dynamic, the operation E as T... more

people

How are primitive data types made in C#?

How do System.float, System.int and other primitives types work? I never understood how it was possible to make primitives structs and I wonder if I could make my own numeric...
Jon Skeet
people
quotationmark

Assuming we're talking about a C# compiler which targets the Common Language Infrastructure (CLI), as almost everything does, it basically uses the primitive types exposed by the CLI. There are effectively three levels of support to... more

people

Does static modifier change the access level of a class member in java?

I am reading the book of OCA & OCP for java 7 certification and I am trying the exercises of the book with java 8 and I noticed something wired. I have Class1 class as...
Jon Skeet
people
quotationmark

Everything is fine - that's how protected access is meant to work. It's specified in JLS 6.6.2.1: Let C be the class in which a protected member is declared. Access is permitted only within the body of a subclass S of C. In... more

people

Why does C# is keyword return true for double, but false for float even though casting to float works?

Motivation: I have a method that returns a dynamic datatype. The value is coming from a database and I know that the value will either be a float, double, or string. I don't...
Jon Skeet
people
quotationmark

Right, this is because the type is dynamic. That basically means the meaning of the float cast depends on the execution-time type of the value. The is operator is checking whether float and double are the same type - and they're not,... more

people

C# Right usage for (number & number) from C++?

I have the following C++ lines: if(fromPos.x == 0xFFFF){ if(fromPos.y & 0x40){ fromIndex = static_cast<uint8_t>(fromPos.z); } else{ ...
Jon Skeet
people
quotationmark

In C++, the condition in an if statement doesn't have to be a Boolean expression - but it does in C#. You just need to check for the result being non-zero: if ((fromPos.y & 0x40) != 0) (The brackets are required due to precedence;... more

people

Adding Complex Keys in the Dictionary! Does it effect the performance

I am just writing a program that requires Dictionary as (in C#.net-4.5) Dictionary<List<Button>, String> Label_Group = new Dictionary<List<Button>,...
Jon Skeet
people
quotationmark

In fact, the lookup based on a List<Button> will be faster than based on a string, because List<T> doesn't override Equals. Your keys will just be compared by reference effectively - which is blazingly cheap. Compare that with... more

people

How to Convert XElement to XComment (C#)

My first question here... I'm parsing xml file (using c# as Xdocument) and trying to disable some xElement objects. the standard way (where I work) is to make them appear as...
Jon Skeet
people
quotationmark

Well it's not quite as you were asking for, but this does replace an element with a commented version: using System; using System.Xml.Linq; public class Test { static void Main() { var doc = new XDocument( ... more

people

Where does the LINQ query syntax come from?

I'm new to C# and have just started to delve into using classes that essentially mirror a database. What I'm confused about is how I'm able to use lines like var...
Jon Skeet
people
quotationmark

From what I understand, that syntax isn't "normal" C# Yes it is, as of C# 3. so the above line wouldn't have any meaning if I hadn't included System.Linq Yes it would. It would still have effectively been transformed by the... more

people