Browsing 7239 questions and answers with Jon Skeet

NotifyPropertyChanged in .Net 4

I have code like this private decimal m_Amount; public decimal Amount { get { return m_Amount; } set { m_Amount = value; ...
Jon Skeet
people
quotationmark

Well, if you use a C# 5 compiler (VS2012/VS2013) and the Microsoft.Bcl NuGet package, you can use CallerMemberNameAttribute with .NET 4. You'll still need to declare the field separately though, because you can't just use an... more 3/5/2014 12:46:23 PM

people

String to Byte[] and Byte to String

Given the following example: String f="FF00000000000000"; byte[] bytes = DatatypeConverter.parseHexBinary(f); String f2= new String (bytes); I want the output to be...
Jon Skeet
people
quotationmark

You're currently trying to interpret the bytes as if they were text encoded using the platform default encoding (UTF-8, ISO-8859-1 or whatever). That's not what you actually want to do at all - you want to convert it back to hex. For... more 3/5/2014 11:52:09 AM

people

Return types in Java long to int casting IntelliJ complains?

So I have this method: So why is IntelliJ warning me that return x is not allowed there, but it is ok just above? The id of class ProjectElement is also of type long. Please...
Jon Skeet
people
quotationmark

I assume by "it is ok just above" you refer to is: return (p1.getId().compareTo(p2.getId()); That's not returning the ID (which is a Long) - it's returning the result of the compareTo method, which is an int. (See the... more 3/5/2014 11:33:09 AM

people

Why doesn't winform open without Application.Run()?

I tried to show a winform with the code below but it opens and immediately closes. I couldn't understand the reason for this.Any ideas? [STAThread] static void Main() ...
Jon Skeet
people
quotationmark

Application.Run runs the message loop which basically handles UI events etc until all the visible windows have shut. The method blocks until the message loop has shut down. You need that message loop to be running in order to keep the UI... more 3/5/2014 10:15:30 AM

people

EF code first cannot convert type to int

I am creating a function on my restaurant review website that gets the cuisine of the last review and then finds other reviews with same cuisine that have a higher average score....
Jon Skeet
people
quotationmark

It's unclear why you'd want to get a review ID at all. You're only interested in the scores for those reviews, right? I suspect you actually want to take part of your first query and part of your second: var averageScoreForCuisine = (from... more 3/5/2014 9:56:28 AM

people

calling a function from within a lambda

Is there a way to call a function from within a lambda expression? we currently have the following var obj = m.Select(x => x.ToDictionary(y => y.ColumnName, y =>...
Jon Skeet
people
quotationmark

The problem with what you've tried is just the arguments to the BuildNewContent method - you're providing lambda expressions when they should just be values. So I suspect you want: var obj = m.Select(x => x.ToDictionary(y =>... more 3/5/2014 9:24:22 AM

people

compare to strings having same characters or alphabets

I am new to Java programming and recently started working on string operations. Can anyone suggest me a working idea to check whether to string consists of same character...
Jon Skeet
people
quotationmark

It sounds like you're trying to check whether the set of characters contained within one string is the same as the set of characters contained within another. That's reasonably easy to achieve with a Set<Character>: static boolean... more 3/5/2014 8:48:39 AM

people

Accept TCP Client Async

I've been making a server. I am using TcpListener.AcceptTcpClientAsync() in an async method, but I have no idea how to actually make it work. My code right now is: private...
Jon Skeet
people
quotationmark

Nothing will magically create dedicated threads for you, although there are some threads used for IO completion which can come into play, particularly if you don't have a synchronization context that you need to return to. You should... more 3/5/2014 6:52:00 AM

people

Reflect op_implicit table

I'm currently looking to build dynamic type converter, for example, I can easily do : public struct Tester { public int Hello; public static implicit operator...
Jon Skeet
people
quotationmark

The operators for the primitive types aren't defined in the framework - they're part of the CLI itself; they have their own special instructions, basically. There's no IL involved, no methods, so nothing for a MethodInfo to refer to. If... more 3/4/2014 3:44:50 PM

people

Java When is the 0th local variable not 'this'?

In the local variables of a Java method, when will the 0th local variable not refer to 'this'? I can think of static methods as a counterexample, are there any others? UPDATE:...
Jon Skeet
people
quotationmark

The JVM specification section 2.6.1 seems to think that it only depends on whether it's a static (class) method or an instance method: The Java Virtual Machine uses local variables to pass parameters on method invocation. On class... more 3/4/2014 2:43:39 PM

people