Browsing 7239 questions and answers with Jon Skeet

function overloading unsolved example

public class Roshni { void sum(int i, int j) { System.out.println("inside 1st i = " + i); } void sum(short i, int j) { System.out.println("inside 2nd...
Jon Skeet
people
quotationmark

This isn't a matter of overload resolution - your method with the short parameter isn't even applicable. Here's an example: public class Test { public static void foo(short x) { } public static void main(String[]... more 9/16/2015 6:09:24 AM

people

Dynamic way to flatten arrays in classes?

I'm iterating through objects that contains an array of doubles. Names changed. Imagine this is an object of Lab samples, and I'm trying to get a flat representation of the Sample...
Jon Skeet
people
quotationmark

I want the each item in the resulting list to have the Name and as many doubles as there are RawReads. You can't do that using anonymous types. Anonymous types have property names and types specified at compile-time whereas you're... more 9/15/2015 3:08:39 PM

people

C# iterating over Dictionary by arbitrary order

I have a Dictionary<string, List<Object>>. I loop through the keys of the dictionary and display the values grouped by the key. I know about SortedDictionary and...
Jon Skeet
people
quotationmark

You don't sort a Dictionary<,> at all. However, if you want to iterate over the entries (or keys) in a particular order, you can use LINQ's OrderBy - and to iterate a known set of values in that order, you can just have the ordered... more 9/15/2015 1:20:34 PM

people

Covariance in List

How can we design following model properly? I have two class Library. Library 2 has reference of Library 1. But Library 1 doesn't have reference of Library 2. Library 1: public...
Jon Skeet
people
quotationmark

You can't make List<T> covariant - it's invariant, and there's nothing you can do about that. You can't treat a List<Apple> as a List<Fruit> because you can't call list.Add(new Orange()) on it, for example. It seems to... more 9/15/2015 12:52:50 PM

people

c# Linq to XML to Object not working in XAMARIN (ios)

i have a problem to get an xml result from a webservice into a custom class in xamarin (ios). I've calling a Webservice and get the following result: <?xml version="1.0"...
Jon Skeet
people
quotationmark

There are a couple of problems here. Firstly, I believe you've got too many calls to Elements/Descendants so you're actually iterating over all the descendants of <CO_App_Table_CO_VERTRETERFTPLOGIN>. Next, you haven't specified the... more 9/15/2015 12:32:14 PM

people

Sort date by value In Xml c#

I'm trying to sort the date-tags in my XML by value: var noteElements = xDoc.Root.Descendants("Note").OrderBy(o => (DateTime)o.Element("date")).ToList(); foreach (XElement...
Jon Skeet
people
quotationmark

You're replacing each Note element with a notedate element. The order in which you perform that replacement is irrelevant. It sounds like you actually want something like: var notes =... more 9/14/2015 10:06:26 AM

people

Reading result from linq select query

I have two list (A & B) both of the same custom type (shown below) MyClass { id as string acidity as double region as string } I need to loop through list A and...
Jon Skeet
people
quotationmark

Okay, it sounds like you probably want a join so that you can identify pairs, then you can copy the regions: var query = from itemA in listA join itemB in listB on itemA.id equals itemB.id select new { itemA, itemB... more 9/14/2015 8:59:16 AM

people

Dictionary initialization access to Key value

I have this situation : public Class Device { } public Class Response { Response(Device device){ ... } } public class DeviceManager { private Dictionary<Device,...
Jon Skeet
people
quotationmark

You can't do that in a field initializer. You'd have to put it in a constructor: public class DeviceManager { private Dictionary<Device, Response> behaviours = new Dictionary<Device, Behaviour>(); public... more 9/14/2015 7:37:09 AM

people

not able to load properties file with runnable jar

I have maven project in Java in which I have a property file (quartz.properties) under this directory: /src/main/resources Now I can use this property file in two ways from...
Jon Skeet
people
quotationmark

Your file is in the jar file as resources/quartz.properties, not just quartz.properties - so that's how you need to load it: factory.initialize( ... more 9/14/2015 6:03:58 AM

people

How to load Jar file in my program?

I'm trying to write a program that load classes and jar files .My app handle the plus operator .For this I have 2 class and one jar file : 1- Operator interface jar file in...
Jon Skeet
people
quotationmark

Currently you're only using D:\ in your classpath: File file = new File("D:\\"); URI uri = file.toURI(); URL[] urls = new URL[] {uri.toURL} ClassLoader classloader = new URLClassLoader (urls); If you want to use a jar file, you should... more 9/14/2015 5:50:13 AM

people