Browsing 7239 questions and answers with Jon Skeet

Duplicate objects in ArrayList are references to a single one?

I have an ArrayList that has some objects that I defined in it. Based on some criteria, I want to copy some of the objects from the first list to the second list (which starts...
Jon Skeet
people
quotationmark

It's always a reference. The value of an expression, the value in an array etc is always either a reference or a primitive value. Nothing will copy an object implicitly - you'd have to do that explicitly. (As an aside, you should follow... more 12/18/2013 8:51:31 AM

people

C# Ionic.Zip ZIP file , Multi level directory appears

Solution Directory E:\WebSolution\GenerateFiles | NEW HOTEL-4-64-1379.pdf | NEW HOTEL-4-64-1379.xls Correct E:\WebSolution\GenerateFiles | NEW HOTEL-4-64-1379.pdf | NEW...
Jon Skeet
people
quotationmark

Looking at the documentation, I suspect you want to call zip.AddFiles(arrFileName, false, ""); so that the directory hierarchy isn't preserved. It's possible that just zip.AddFiles(arrFileName, ""); would work too; it's not entirely... more 12/18/2013 8:47:45 AM

people

MessageDigges md5 differs from the database md5 string

MessageDigest md = MessageDigest.getInstance("MD5"); String md5password = new String(md.digest("test".getBytes("UTF-8")), "UTF-8"); I have the same string "test" in my...
Jon Skeet
people
quotationmark

This is the problem: new String(md.digest("test".getBytes("UTF-8")), "UTF-8"); You're trying to decode the result of the MD5 digest as if it were a UTF-8 string. It's not. It's not text at all - it's just binary data. What you're doing... more 12/18/2013 8:20:41 AM

people

Load XDocument into HTML unsorted list

I'm trying to load a Unsorted List from XML file. The parents tags must be loaded into ul and children tags into ol. The problem is, i can't get the parent alone, it always...
Jon Skeet
people
quotationmark

I suspect this is the problem: <ul>@parent.Value</ul> That's closing the <ul> tag, rather than including each of the child elements within it. The reason you're getting the CHILED elements twice is that you're using... more 12/18/2013 8:09:22 AM

people

How can I get an address of a List?

I need to check if a returned list was created once or if it's a copy of an object. Is it possible to find out it's address? // thread 1 List<Object> list =...
Jon Skeet
people
quotationmark

Is it possible to find out it's address? No. You can, however, check for reference equality - which is all you care about: if (list1 == list2) { // They're the same } If you really want to do this from logging, you can use... more 12/17/2013 4:01:23 PM

people

Error converting LINQ anonymous type to IList<>

I have the following LINQ join: var query = _ABC.Table .Join(_DEF.Table, cef => ...etc... }) .Join(_GHI.Table, extf => ...etc...}) ...
Jon Skeet
people
quotationmark

Well yes - query.ToList() will return a List<T>, which doesn't implement IQueryable<T>. Indeed, the ToList() would render the paging less useful, as it would all be done locally after fetching the whole table into memory. Just... more 12/17/2013 3:39:22 PM

people

Identifying Unique Values in a C# List

I have created a class, as below, to represent a Composite Primary Key model: public class PrimaryKeyModel { public string ColumnName { get; set; } public string...
Jon Skeet
people
quotationmark

EDIT: I may well have misread the question, and inferred too much from your class name being PrimaryKeyModel - I had interpreted that to be a model for a primary key, and that you wanted to find duplicate primary keys. If that's not the... more 12/17/2013 3:20:12 PM

people

Socket data type giving error even after importing java.net.*;

I was using the below code for Socket connection in Java and it is giving an error that Socket data type doesn't exist even after importing java.net.*; But when I declare the...
Jon Skeet
people
quotationmark

Yes, this is the problem: while (Socket con = dtserver.accept ()) The while statement needs a boolean condition - and a Socket isn't a boolean. (And you can't declare a variable in a while condition either...) You probably want: while... more 12/17/2013 2:50:45 PM

people

Print different length of spaces in C#

How can I print different length of spaces in C#? Write(number*" "); doesn't work here. EDIT: But it works in Python.
Jon Skeet
people
quotationmark

Indeed, there's no * operator taking a string and an integer. The simplest option is probably to use the string(char, int) constructor: Write(new string(' ', number)); Depending on your actual use case, you might want to look at... more 12/17/2013 11:22:16 AM

people

In socket programming I am getting error on receiving string on the server side which has code written in c

This is my C server code. I am sending a string from java to c using socket connection. #include <stdio.h> #include <unistd.h> #include <string.h> #include...
Jon Skeet
people
quotationmark

DataOutputStream.writeUTF doesn't just write the characters out in a way that C is going to understand: It uses a modified version of UTF-8 It prepends the length of the string You could write code in C to handle that, but you'd need... more 12/17/2013 10:04:10 AM

people