Browsing 7239 questions and answers with Jon Skeet

Format of DateTime that SQL Server uses

I am debugging a query that is getting built in C# maybe with EntityFrameWork - not sure - but it doesn't return any records although it should. The query has some DateTime fields...
Jon Skeet
people
quotationmark

Formatting is irrelevant. Internally it won't be in a text format at all, and I'd hope that the query doesn't end up sending the query value to the database as text either. If you're only interested in the date part, you need to say that... more 11/27/2013 10:15:30 PM

people

How to EnumerateFiles with all subdirectories with C# DirectoryInfo?

I found this code that gets an array of files out of a DirectoryInfo : FileInfo[] fileInfoArray = di.EnumerateFiles().Where(f =>...
Jon Skeet
people
quotationmark

Look at the overloads of DirectoryInfo.EnumerateFiles - there's no overload taking just a SearchOption, but you can give a string and a SearchOption: var files = di.EnumerateFiles("*", SearchOption.AllDirectories) .Where(f... more 11/27/2013 10:04:44 PM

people

c# Path.Combine isn't working right?

I'm trying to combine a path and a string to create a path, although the path is the string only? what I mean is, when I use Console.WriteLine(filepath) all that comes out is the...
Jon Skeet
people
quotationmark

You shouldn't have the \ at the start of the second argument. You want: string filepath = Path.Combine(arg1, "tf1.dat"); Otherwise it thinks you want an absolute filename, basically. more 11/27/2013 9:04:54 PM

people

Conversion of AtomicInteger to int

I wrote a thread and for memory synchronization I have to use Atomicinteger. Here is my code: public class NewClass implements Runnable { public double rr; public double...
Jon Skeet
people
quotationmark

If you're trying to use the same value throughout the loop, just use the return value of incrementAndGet(): int index = q.incrementAndGet(); if (index >= Xdisc.length) { break; } // I'm assuming you meant there to be a brace... more 11/27/2013 6:02:59 PM

people

How to calculate round on very large array of double in C#

In C# I have an array of double (double[] I mean) I want to round all values to two decimal places in C#. One solution is to do this with foreach() and Math.Round() functions but...
Jon Skeet
people
quotationmark

Instead of foreach, a more efficient solution? Nope. Fundamentally, if you want to round all the values, you've got to round all the values. There's no magic that will make that simpler. Of course, if you're only going to access a... more 11/27/2013 5:48:06 PM

people

Convert BitArray to a small byte array

I've read the other posts on BitArray conversions and tried several myself but none seem to deliver the results I want. My situation is as such, I have some c# code that controls...
Jon Skeet
people
quotationmark

Well you could use BitArray.CopyTo: byte[] bytes = new byte[4]; ba.CopyTo(bytes, 0); Or: int[] ints = new int[1]; ba.CopyTo(ints, 0); It's not clear what you'd want the string representation to be though - you're dealing with... more 11/27/2013 4:14:11 PM

people

How to filter LINQ with date

my code: var query = from s in ctx.location join b in ctx.order on s.locationID equals b.ID join e in ctx.offerdata on b.OrderID equals...
Jon Skeet
people
quotationmark

Well you're really interested in the year, right? So try: where e.delDate.Year == 2013 EDIT: As we now know that delDate is a DateTime? it would be: where e.delDate != null && e.delDate.Value.Year == 2013 more 11/27/2013 3:10:51 PM

people

How can I convert from packets to bytes

In .NET 4, I'm using IPGlobalStatistics class. The properties OutputPacketRequests, OutputPacketsDiscarded, etc in this class are referred in packets. How can I convert these...
Jon Skeet
people
quotationmark

You can't. Packets can be of different sizes, so there's no single mapping from "number of packets" to "number of bytes". (That class only gives the numbers of packets - not the contents of the packets themselves.) more 11/27/2013 10:21:41 AM

people

Do we have conditional compiling in java like c?

Do we have a replacement of these kind of statement in java ? #ifdef MacOSX #import <Cocoa/Cocoa.h> #else #import <Foundation/Foundation.h> #endif I want...
Jon Skeet
people
quotationmark

No, Java doesn't have anything like that. While the compiler can strip out code which is guaranteed not to be executed, it's still got to be valid code. So you can have: private static final FOO_ENABLED = false; ... if (FOO_ENABLED) { ... more 11/27/2013 10:00:35 AM

people

How to concatenate a character to a SQL string in a preparedstatemenet

When I concatenate a character namely tid to this string in Java. I will get where sc.CategoryCode = C But I actually need where sc.CategoryCode = 'C' when I add a single quote...
Jon Skeet
people
quotationmark

You shouldn't build up your SQL like this - you should use parameterized SQL instead: // TODO: Closing the statement etc String sql = "select sc.* from SubCategory sc where sc.CategoryCode = ?"; PreparedStatement statement =... more 11/27/2013 8:42:26 AM

people