Browsing 7239 questions and answers with Jon Skeet

Nested classes lists LINQ

I have the following classes: public class SerializedDelegate { public List<GOEntry> goEntries = new List<GOEntry>(); } public class GOEntry { public string...
Jon Skeet
people
quotationmark

It sounds like you want something like: var lines = from goEntry in sd.goEntries from mbEntry in goEntry.mbEnties from methodEntry in mbEntry.methodsEntries select string.Format("{0}: {1}.{2}", ... more 4/4/2014 3:21:56 PM

people

DateTime.ToString() format error

I am using the following format to convert a DateTime to a string setting.SettingValue = dt.ToString( "yyyy-MM-dd HH:mm:ss.fff" ); however the value is not as expected. The...
Jon Skeet
people
quotationmark

You haven't specified a format provider, so it's using the one from the current culture. If you always want to use :, you should specify an appropriate provider, e.g.: setting.SettingValue = dt.ToString("yyyy-MM-dd HH:mm:ss.fff", ... more 4/4/2014 1:18:53 PM

people

How can a method without the out or ref change a variable outside itself? C#

How is it possible to change the values of an array a from the inside of SumElemtnts method? Is it because it's a static method? Because the method returns only the variable sum...
Jon Skeet
people
quotationmark

You're not changing the value of the variable within SumElements - that still refers to the same array that it did before. Note how there's no assignment to a within the SumElements method. Instead, you're changing the contents of the... more 4/4/2014 12:14:02 PM

people

Switch between types including interfaces

I have a set of overloads for a get function. Each one have a different input type but basically the same signature schema (as follow): string GetPropertyValue(int propId, string...
Jon Skeet
people
quotationmark

You can't look the type up in the dictionary that way. You'll have to loop through the key-value pairs: Type targetType = defaultValue.GetType(); foreach (var pair in dictionary) { if (pair.Key.IsAssignableFrom(targetType)) { ... more 4/4/2014 11:24:43 AM

people

Unit test Distinct with keyselector and comparer

How would I go about unit testing this piece of LINQ code? public static IEnumerable<T> Distinct<T, TKey>(this IEnumerable<T> items, Func<T, TKey>...
Jon Skeet
people
quotationmark

This code is trying to do something similar to MoreLINQ's DistinctBy method, but not as well. Fundamentally, the idea is that given a collection of items, you want to find a distinct set of items, but specifically testing for distinctness... more 4/4/2014 9:06:25 AM

people

how java inner class objects exists in the memory heap?

class Outer { int o = 10; class Inner { int i = 20; } } public class Demo { public static void main(String args[]) { Outer o = new Outer(); ...
Jon Skeet
people
quotationmark

Basically the compiler implicitly creates a constructor taking a reference to the outer class, which is stored in a hidden field. So your code is somewhat like this: class Outer { int o = 10; static class Inner { private... more 4/4/2014 8:47:41 AM

people

How to get the ASCII value of a string

Suppose there is a string: String str="Hello"; HOw can i get the ASCII value of that above mentioned string?
Jon Skeet
people
quotationmark

Given your comment, it sounds like all you need is: char[] chars = str.ToCharArray(); Array.Sort(chars); A char value in .NET is actually a UTF-16 code unit, but for all ASCII characters, the UTF-16 code unit value is the same as the... more 4/4/2014 6:52:05 AM

people

Invoke Delegate With Right Type

I have a parameter of type object. Anything can be set on that parameter. And I need to find the property with a certain name in that parameter. If it exists of course. I need...
Jon Skeet
people
quotationmark

Two options to consider: Use dynamic typing to call a generic method which will return you a Func<object, object> which you can use later by wrapping up an expression-tree-compiled delegate: public Func<Object, Object>... more 4/4/2014 6:49:13 AM

people

java code to assign two minutes as a time interval

String qtm = "00:02:00"; SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); java.util.Date d = null; try { d = formatter.parse(qtm);} catch...
Jon Skeet
people
quotationmark

The problem at the moment is that your SimpleDateFormat is in your local time zone, whereas Date.getTime() gives you the milliseconds since the Unix epoch in UTC. You can fix this as: SimpleDateFormat formatter = new... more 4/4/2014 6:36:46 AM

people

Comparing Lists under multiple conditions

public class ConsumableThreshold { public int ThresholdType { get; set; } public int ManufacturerID { get; set; } public int ModelID { get; set; } public int...
Jon Skeet
people
quotationmark

Sure - you're just trying to join on a compound key, which is usually accomplished with an anonymous type: var query2 = from e in existingThresholds join d in defaultThresholdson on new { e.ThresholdType,... more 4/3/2014 4:12:54 PM

people