Browsing 7239 questions and answers with Jon Skeet

Linq OrderBy in select if count is over 0

I have a query that looks like this: var qContactsOpen = from x in promo.Contacts where x.type == type && (x.closure_id == 0 || x.closure_id == null) orderby x.id...
Jon Skeet
people
quotationmark

It sounds you might just want: Note = x.ContactsActivities .OrderByDescending(o => o.date) .Select(o => o.note) .FirstOrDefault() ?? ""; By putting the projection earlier, it means you end up with the null... more 10/2/2013 4:55:46 PM

people

I get a different C# object instance when calling the constructor from reflection

Compare the two instances of the same class below. The variable instanceA is created using reflection, while instanceB is created using a direct reference to the DLL from my...
Jon Skeet
people
quotationmark

The problem is that you've got different assemblies - in one case you've loaded an assembly just from a byte array (which happened to be stored on disk as MyFilePath.dll) and in the other you're referring to the assembly which was loaded... more 10/2/2013 2:08:41 PM

people

Redundant explicit property name in C# warning

I am using the SimpleMembership provider and adding additional fields to be saved on registration. To save additional fields on registration I use the method used everywhere e.g....
Jon Skeet
people
quotationmark

My question are 1) for this anonymous object parameter where I now remove the property names so I don't get the Resharper warnings anymore, how does it know what the property names are since they are passed by value? The names are... more 10/2/2013 2:05:58 PM

people

Are async/await keywords only usable with VS 2012+?

Are async/await keywords only usable with VS 2012+ and not usable with the C# compiler, which I could use from command line? I've read some questions at SO, like: Will VS 2010...
Jon Skeet
people
quotationmark

Are async/await keywords only usable with VS 2012+ and not usable with the C# compiler, which I could use from command line? No, it's fine to build with csc.exe from the command line, so long as it's the C# 5 compiler (as shipped with... more 10/2/2013 12:43:16 PM

people

Why does my GregorianCalendar object return the wrong day of week?

My issue is seemingly extremely simple. I make a calendar graphic user interface, from a GregorianCalendar object, and uses it's methods to calculate the correct number of days in...
Jon Skeet
people
quotationmark

I refuse to put in a "-1" in my code, to wrongly correct the symptoms of what is obviously a mistake. The mistake is your assumption that Calendar.get(Calendar.DAY_OF_WEEK) is localized. It isn't. The mapping between day-of-week and... more 10/2/2013 12:00:08 PM

people

Programmatically compiling .java files, error

When run this code to compile a .java file in this directory: String title = txtName.getText(); String name = title + ".Java"; String src =...
Jon Skeet
people
quotationmark

Your filename ends with .Java - it should be .java. Otherwise the compiler doesn't expect it to be a source file, and tries to process it as a flag instead. more 10/2/2013 10:58:46 AM

people

Convert SQL Date time format to String

when reading SQl Date time field , only i can take the date with time ..how to get only date in to text box from Ajax or some method. this is what i need to...
Jon Skeet
people
quotationmark

Don't convert the raw value to a string in the first place - it should already be a DateTime: DateTime date = (DateTime) dsr["ExpireDate"]; Then you can convert it into whatever format you're interested in: // TODO: Consider specifying... more 10/2/2013 10:55:08 AM

people

Why is my start method undefined for the timer class?

import javax.swing.*; import java.awt.FlowLayout; import java.awt.event.*; import java.util.*; import javax.swing.Timer.*; class Timer { public static void main(String[]...
Jon Skeet
people
quotationmark

The problem is that you're declaring your own Timer class - so Timer t = new Timer() is referring to your class rather than javax.swing.Timer, and you don't declare a start method. I'm pretty sure you want to use the javax.swing.Timer... more 10/2/2013 9:40:27 AM

people

byte[] won't parse to an image

I have this custom adapter for my listview that is getting filled with a ArrayList of a custom rowItem class where I put data in. rowItem.getImage() will return this byte array:...
Jon Skeet
people
quotationmark

What you've shown isn't a byte array - it's text, which looks very much like base64 data. You should try decoding it from base64 to "raw" bytes first: byte[] imageData = Base64.decode(rowItem.getImage(), Base64.DEFAULT); ... or fix... more 10/2/2013 9:35:47 AM

people

Working with object

consider the variable ob4 as shown in figure now : how can i reach ob4[0]-[0,2] var o=ob4[0]; double[,] p=(double[,]) o[0,0]; the line (double[,] p=(double[,]) o[0,0];) gives...
Jon Skeet
people
quotationmark

You need to cast o[0, 0] to object[,] first: var o = (object[,]) ob4[0]; double[,] p = (double[,]) o[0, 0]; It would be better if you could avoid having all these nested multi-dimensional arrays with so little type information at... more 10/2/2013 9:03:16 AM

people