Browsing 7239 questions and answers with Jon Skeet

check if collection of objects where each contain another collection of objects contain all values of List<string> via LINQ

I have a collection of objects where each object contains another collection of objects. I need to find out the fastest way to check if it contains all values of...
Jon Skeet
people
quotationmark

With your current code, you logically want: IEnumerable<Video> result = from vid in videos where selectedTags.All(tag => vid.Tags.Any(t => t.Name == tag)) ... more 3/26/2014 3:53:44 PM

people

Why arrays needs dimension set at define time?

I am just wondering, why can't we just define something like this: int[] arr = new int[]; arr[0] = 1; Like a list, to resize automatically. What i want to know is why is this...
Jon Skeet
people
quotationmark

List<T>'s resizing is based on creating a new array behind the scenes when it needs to. Think about what the underlying implementation looks like here. When you allocate an array, it reserves a chunk of memory, and the reference... more 3/26/2014 9:26:38 AM

people

Correct API approach for long processing time

I am making an HTTP web API that's mainly fed by a database. Simplified, the db contains userobjects. These objects have a last_online (when the user was online) and last_checked...
Jon Skeet
people
quotationmark

One fairly "old-school" way of handling this would be to return a continuation token - basically a job ID saying, "Check this periodically; sooner or later it'll come back with a result." Given that even 30 seconds is quite a long time,... more 3/26/2014 8:49:43 AM

people

Settings file types converting

I would like to save the user radio- button preference in the Settings file. Therefore, I have created a setting property called radioButtonIsChecked boolean typed. ...
Jon Skeet
people
quotationmark

Assuming the retrieved value will be of the right type, just cast it: radioButton.Checked = (bool) Properties.Settings.Default[radioButton.Name + "IsChecked"]; more 3/25/2014 12:21:32 PM

people

Error in DateTime insertion

I have encountered below mentioned problem while trying to enter DateTime programatically using c#. ERROR MESSAGE: The conversion of a nvarchar data type to a datetime data...
Jon Skeet
people
quotationmark

This is the problem: SqlParameter pa2 = new SqlParameter("@DTime", DbType.DateTime); pa2.Value = DateTime.Now.ToString(); You've said the parameter is a DateTime, but then you're converting it to a string - and quite possibly doing so... more 3/25/2014 11:17:41 AM

people

Cannot find symbol variable java

I am trying to do the following program in Java where I'm writing a recursive and an iterative method to compute the sum of all odd numbers from n to m import...
Jon Skeet
people
quotationmark

This method is the problem: public static int recursivesum(int n, int m) { if (n < m) { int s = n; // Variable declared here... scoped to the if s += recursivesum(n+2, m); } else { if (m < n) { ... more 3/25/2014 9:38:23 AM

people

Class Inside Method

public class Demo { public void met(Object d) { class my { public String Work(String s){ return s+",JAVA"; } } ...
Jon Skeet
people
quotationmark

can I create object of my class from main method and How? No. Only the met method knows anything about the class. If you want to use the class outside that method, you should declare it either as a nested class within Demo, or as a... more 3/25/2014 8:03:35 AM

people

Difference between creating an object within the constructor vs outside of the constructor?

Within my program, I am trying to create a toolbar within a frame. Within the toolbar, I have three buttons that are represented with a picture instead of text. The problem is...
Jon Skeet
people
quotationmark

In the first case, you just have three local variables declared in the constructor. In the second case, your Tool class has three fields. You can then refer to those fields in other methods, and they are part of the state of the... more 3/24/2014 6:54:30 PM

people

What does it mean to call a function without being bound to an identifier

I understand Lambda expressions in the sense of: delegate int del(int i); static void Main() { del myDelegate = x => x * x; int j = myDelegate(2); ...
Jon Skeet
people
quotationmark

() => is the start of a lambda expression that doesn't have any parameters. It's important to understand that a lambda expression can't exist in a vacuum - it's always part of a conversion to either a delegate type or an expression tree... more 3/24/2014 5:12:11 PM

people

Is there a difference between cast and strong type assignment?

I sort of ran into this today when writing some code. Take the following as an example: long valueCast = (long)(10 + intVariable); long valueTyped = 10L + intVariable; Is...
Jon Skeet
people
quotationmark

Yes, there's a big difference between those two. Not for those particular values, but the exact same expression with different values will show the difference. In the first version, the addition is done in 32-bit arithmetic, and then the... more 3/24/2014 2:57:43 PM

people