Browsing 7239 questions and answers with Jon Skeet

Adding XML Content in string to XDocument

I have to make an xml like this and post to a url on fly <Student> <Name>John</Name> <Age>17</Age> <Marks> <Subject> ...
Jon Skeet
people
quotationmark

Just parse marksxml as an XElement and add that: XDocument doc = new XDocument( new XElement("Student", new XElement("Name", "John"), new XElement("Age", "17"), XElement.Parse(marksxml) ); ) more 6/19/2015 6:20:41 AM

people

& Turns into &amp; in metadata

I have a simple problem regarding &amp. I decided to upload a simple csv file just to insert meta title and meta description. It uploaded sucessfully but when i use the view...
Jon Skeet
people
quotationmark

My question is how do i change &amp; into & ? I wouldn't, if I were you. &amp; is just the HTML-encoded (and XML-encoded) form of &. The browser will display it as &. I don't know offhand whether an & followed... more 6/19/2015 6:15:38 AM

people

Multiplication of numbers as string

Why is '0' subtracted from n1.charAt(i) and n2.charAt(j)? Question: Given two numbers represented as strings, return multiplication of the numbers as a string. public String...
Jon Skeet
people
quotationmark

Why is '0' subtracted from n1.charAt(i) and n2.charAt(j) ? Because the number of the Unicode character representing the digit 0 is 48, not 0. Imagine you wanted to label 'A' = 0, 'B' = 1 etc... then you'd use n1.charAt(i) -... more 6/19/2015 5:11:49 AM

people

Generic constraint of X AND Y

Can generic constraints be used to enforce a constraint on type derivatives of an abstract class, but only those that implement an interface? Example: abstract class...
Jon Skeet
people
quotationmark

Sounds like you're just missing the ability to specify both a class and interfaces as a comma-separated list in the constraints: static void INeedToDoBoth<T>(T dependency) where T : Dependency, IOptionalDependency Note that... more 6/18/2015 5:20:43 PM

people

Why does the "this" keyword refer to the subclass too?

In the following scenario, Main.registerEvents(Listener) is part of an event system of a game API. Let's say it should register any method with the @EventHandler...
Jon Skeet
people
quotationmark

Generally speaking, since this refers to the current instance, how is it possible that Fireball.onChat(PlayerChatEvent) is registered too? Because when you're constructing an instance of Fireball, this refers to the Fireball being... more 6/18/2015 2:44:08 PM

people

Find string in enum

Is there a way to find part of a string in an enum like this: Status.Find("InStock"); public enum Status { Unknown, InStock, InStockReserved, Taken, ...
Jon Skeet
people
quotationmark

Sounds like you want something like: var integers = Enum.GetValues(typeof(Status)) .Cast<Status>() .Where(status => status.ToString().Contains("InStock")) .Select(status... more 6/18/2015 2:36:17 PM

people

Object is currently in use somewhere else error when using Paraller.For

I am trying to parallelize an operation on an image using the code below , but I get an One or more errors occurred error. Looking into the inner exception I can see the error...
Jon Skeet
people
quotationmark

It looks like you're trying to use image APIs from non-UI threads. That's a bad idea. I suggest you copy the image to a byte array on the UI thread, then run your parallel for loop which would mutate the array, then recreate the image... more 6/18/2015 2:09:33 PM

people

Linq to get difference of two listviews and put it in third in Windows Form C#

I have two list views which have same data but differing in the number of records. I want to get the non-matching listviewitems in third list view. I have using the following code...
Jon Skeet
people
quotationmark

LINQ doesn't have a "set difference" operator itself... but you can use Except twice: var list1Text = list1Source.Select(x => x.Text); var list2Text = list2Source.Select(x => x.Text); var difference = list1Text.Except(list2Text) ... more 6/18/2015 11:10:34 AM

people

C# Reflection Call Method with ref/Pointer Parameter

I want to call with reflection each Method of an Class but I cant call Methods with an pointer as Reference. Normally I just could pass null for each pointer I find and everything...
Jon Skeet
people
quotationmark

First, let's separate this into pointer vs ref - they're handled slightly differently. It's not clear what pointer value you expected the method to receive - particularly as the value you passed to Invoke was a type, not an instance of... more 6/18/2015 10:53:41 AM

people

Need to fetch Oracle RAW in C# string datatype "as is"

Help me out, requirement is that I need the same value of Oracle RAW to be in C# as a string. I am able to save String as RAW value in oracle table, but while fetching it is...
Jon Skeet
people
quotationmark

The RAW datatype is documented as: The RAW and LONG RAW datatypes are used for data that is not to be interpreted (not converted when moving data between different systems) by Oracle Database. These datatypes are intended for binary... more 6/18/2015 9:22:18 AM

people