Browsing 7239 questions and answers with Jon Skeet

C# string comparison failure

My application is failing on a string comparison. I have put in a breakpoint and then used the intermediate window of Visual Studio and done the following...
Jon Skeet
people
quotationmark

It sounds like there may well be an unprintable character between the "s" and the "". I usually use something like this to show the true contents of a string: for (int i = 0; i < text.Length; i++) { Console.WriteLine("{0:x4}",... more 1/6/2015 10:03:46 AM

people

C# Can't declare a pointer variable in structure

I work in Visual Studio 2012. I am just trying to create structure with pointers to same structure: namespace PLT_1_lab { class Program { struct tNode { ...
Jon Skeet
people
quotationmark

Matthew's answer is probably the most appropriate way to go, but just to explain why the compiler is complaining... From the C# 5 specification, section 18.2 (pointer types): A pointer-type is written as an unmanaged-type or the... more 1/6/2015 10:00:31 AM

people

is class locking related to java classloader?

Looks like I am missing important concept on locking a class and it's related classloading event.As per my knowledge in java we can use any class only if classloader has already...
Jon Skeet
people
quotationmark

The class will have been loaded, but not necessarily initialized. Basically, there's a Class object available when you synchronize on it, but until something uses a member of the class, it doesn't have to be initialized. From the JVM... more 1/6/2015 3:15:18 AM

people

BigDecimal.valueOf caching mechanism

I heard that the BigDecimal.valueOf() method is better than calling new BigDecimal() because it caches common values. I wanted to know how the caching mechanism of valueOf works.
Jon Skeet
people
quotationmark

Looking at the JDK 1.8 sources, it looks like it's just a static array which is initialized as part of class initialization - it only caches the values 0 to 10 inclusive, but that's an implementation detail. For example, given... more 1/5/2015 8:53:24 AM

people

Cannot implicitly convert type 'object' to 'bool'

why do I have to cast an object when I assign its value to a variable, but if I used the GetType() function it returns its value. Sorry my English is bad, but I hope you...
Jon Skeet
people
quotationmark

You need to understand the difference between the compile-time type of a variable, and the execution-time type of its value. The compiler uses the compile-time type to look up members (e.g. methods) and work out what conversions are... more 1/4/2015 5:04:06 PM

people

How to refer a Lambda?

How can I refer a Lambda from inside of it, if, for example, I need to use myLambda recursively? myLambda -> {expression} // ^^^^^^^^^^ how can I refer to myLambda...
Jon Skeet
people
quotationmark

If you mean you want to refer to the lambda expression you're defining within that lambda expression, I don't believe there's any such mechanism. I know of a few cases where it would be useful - recursive definitions, basically - but I... more 1/4/2015 4:47:15 PM

people

What is the final format for string interpolation in VS 2015?

I can't get string interpolation to work. Last news from MS I found was http://blogs.msdn.com/b/csharpfaq/archive/2014/11/20/new-features-in-c-6.aspx However all that is said...
Jon Skeet
people
quotationmark

Your first form did work in the VS2015 Preview: int i = 42; var s = "\{i}"; That compiled and ran for me. ReSharper complained, but that's a different matter. For the final release of C#, it is: var s = $"{i}"; more 1/4/2015 3:43:06 PM

people

Is it possible to detect message type in protobuf csharp port?

A java client constructs a Message according to this skeleton : package tutorial; option java_package = "com.example.sff.piki2"; option java_outer_classname =...
Jon Skeet
people
quotationmark

Is there anyway I can know if this is a MSG message or a "Heartbeat" message? No. Protocol buffer messages don't contain any such type information. Typically the way round this is to have a "wrapper" type with a field for each message... more 1/4/2015 8:47:49 AM

people

Arrays concept in JAVA

Consider the two ways of declaring an array type variable in Java: 1) Syntax : dataType[] arrayRefVar; Example: double[] myList; 2) Syntax: dataType...
Jon Skeet
people
quotationmark

In the first example, all the type information is in one place - the type of the variable is "array of dataType" so that's what the dataType[] says. Why would you have two aspects of the type information in different places - one with the... more 1/4/2015 8:13:56 AM

people

How to subtract a number(int) from a character in java

Hi I'm trying to subtract an int from a char but I keep being told that the compiler "cannot convert from int to char". I have tried changing the constant to a char but it didn't...
Jon Skeet
people
quotationmark

The problem is that subtraction is never performed on char values in Java. Instead, both operands are promoted to int (via binary numeric promotion), and the result of the subtraction is an int as well. So you'll need to cast the result... more 1/3/2015 7:47:43 PM

people