Browsing 7239 questions and answers with Jon Skeet

Foreach (line.contains("id") in reader.readline())

recently i started to make a user-interface manager based on .nui file(s), they look like this : begin genwnd id = addinformation_creature; spr = ui_frame.spr; rect =...
Jon Skeet
people
quotationmark

It's not really clear what you mean, but I suspect you just want to keep a reference to the "current node" - which you change when you get a new ID. So: TreeNode node = null; while ((line = reader.ReadLine()) != "end") { if... more 8/21/2014 9:26:16 AM

people

How to get the time of specific timezone using C#,?

Good Day I need to determine the time (DateTime object) in the Australian Western Standard Time regardless what the user's local time zone is set time zone can be anything i will...
Jon Skeet
people
quotationmark

It's not really clear what you're trying to achieve, but if you just want to get the current time in a particular time zone, you can use: // No need to call Convert.ToString - it's already a string! string zoneId = "W. Australia Standard... more 8/21/2014 8:59:14 AM

people

Java protected modifier accessible in another package having the same package name

I have programmed in Java for some time and I just realized that the protected access modifier allows members to be accessed also in the same package. So here is the situation and...
Jon Skeet
people
quotationmark

If the package names are the same, the two classes are in the same package - it's as simple as that. The fact that they were built from different source directories is irrelevant - the only thing that identifies a package is its... more 8/21/2014 8:42:02 AM

people

Why does Contains() return false but wrapping in a list and Intersect() returns true?

Problem: When I use Contains() against an IEnumerable<T> of classes that correctly implement IEquatable and override GetHashCode it returns false. If I wrap the match...
Jon Skeet
people
quotationmark

Okay - the problem is actually in the array implementation of ICollection<T>.Contains. You can see that simply like this: static void Main(string[] args) { var ab = new MyEquatable("A", "B"); var target = new... more 8/21/2014 6:58:04 AM

people

Conditional Anonymous type

I am working on Web API and using Anonymous type to make JSON as output. I am stuck in the following scenario: If there is no record(VALUE) available then i don't want to show...
Jon Skeet
people
quotationmark

The properties of an anonymous type are fixed at compile-time - you can't make them conditional. However, some other approaches you might want to think about: You could investigate whether a property is still included in the JSON... more 8/21/2014 6:40:03 AM

people

Why is everything getting cast to int?

I have a table in a sql server database with a year column of type shortint and a qtr column of type tinyint. When this table is imported with entity framework, the types of the...
Jon Skeet
people
quotationmark

Why is everything getting cast to an int for comparisons? Because that's what the C# language defines. It doesn't define any operators on byte, short etc - they're all promoted to int before anything happens. That gets propagated to... more 8/20/2014 8:17:35 PM

people

How to format XML string by means of C++.Net?

I have a string, in which there are plenty of XML code. I'd like to write this string to file so that it will be well-formatted (with indentation), like: <table> ...
Jon Skeet
people
quotationmark

I wouldn't use LINQ itself at all. I'd just use an XML API - probably LINQ to XML. Don't be fooled - the "LINQ" in the term really just means it's an API which is designed to work really well with LINQ to Objects. You don't need any... more 8/20/2014 8:08:13 PM

people

Java collection with Incompatible types error

So I have this function, and it's not compiling. What is the problem? The compiling error is Line 4: error: incompatible types public List<List<Integer>>...
Jon Skeet
people
quotationmark

An ArrayList<ArrayList<Integer>> isn't a List<List<Integer>>, for the same reason that an ArrayList<Apple> isn't a List<Fruit>, and it's fairly easy to given an example of why that's the... more 8/20/2014 6:58:30 PM

people

Assessing Xml node values with xmlnamespace

I am trying to access "shl:Value" node using c# but getting null or run time error. I like avoid using big loops. Code: XmlDocument objXmlDoc1 = new...
Jon Skeet
people
quotationmark

If your only requirement is to get at the shl:Value element, then that's really easy with LINQ to XML - I wouldn't personally use XPath to do it: XNamespace shl = "http://www.shl.com"; XDocument doc = XDocument.Load(...); XElement element... more 8/20/2014 5:02:08 PM

people

How to enumerate Object?

I am trying to enumerate Object which is actually enumerable, but the type is stored in Type variable public Type MyListType { get; set; } public Object MyList { get; set;...
Jon Skeet
people
quotationmark

Well if it's actually enumerable, presumably it implements IEnumerable... so you can just use: foreach (object item in (IEnumerable) MyList) { ... } You're not going to have a better compile-time type for item than object anyway... more 8/20/2014 4:48:30 PM

people