Browsing 7239 questions and answers with Jon Skeet

C# File Last Modified time

I am trying to get the last write time of a particular file. This is the code and it works:` DirectoryInfo DR = new DirectoryInfo(folderPath); FileInfo[] FR2 =...
Jon Skeet
people
quotationmark

You don't have to search through a directory to get a FileInfo - you can construct one directly from the full path. It sounds like you just need: var fileInfo = new FileInfo(Path.Combine(folderPath, "InputData.csv")); var lastModified =... more 1/20/2016 9:55:52 PM

people

Difference between ToUniversalTime() and ToLocalTime()

So am not sure which one to use since my understanding of both is limited. The problem that I have is that I want to display the time depending on what time zone the user has set...
Jon Skeet
people
quotationmark

In that case, you would use ToLocalTime()... but that's only going to work if the value from the database is already in UTC. If it's in some other time zone, that's a whole different matter :) In many - but not all - cases, storing UTC in... more 1/20/2016 6:37:02 PM

people

c#: What happens exactly when I initialize an array of bools like this

Im getting into C# and im a little bit confused about an example of the resource im learning from. Its about the declaration and initialisation of a bool array, id like to know...
Jon Skeet
people
quotationmark

I declare a 2 dimensional bool array of unknown size Well, you declare an array of arrays. It's not a "real" multi-dimensional array - that would be bool[,] myBools. It's worth understanding the difference between jagged arrays (an... more 1/20/2016 5:00:29 PM

people

Servlet's service and init method are being called, but not doGet while I am extending ZuulServlet

Before I start, I would say, I have already seen similar question Servlet's service and init method are being called, but not doGet but that dint help me much. Point to be...
Jon Skeet
people
quotationmark

It looks like ZuulServlet isn't meant to be used like this. If you look at the source code of what ZuulServlet.service does, it basically hands everything off to a ZuulRunner. It seems to me that you need to be looking into hooking into... more 1/20/2016 3:16:29 PM

people

Conditional Select after GroupBy

How should I write a conditional Where after a GroupBy to Select items based on a if statement? I have a List of objects of type Option: class Option { public Boolean...
Jon Skeet
people
quotationmark

It sounds like you don't really want to filter by "important" but order by it: Value = g.OrderByDescending(op => op.Important) // true first .ThenByDescending(op => op.Priority) .First() .Value more 1/20/2016 11:17:16 AM

people

Get the "Text" value out of "System.EventArgs objArgs"

As you can see in that screenshot in "objArgs" there is a property "Text". How can I reach that property?
Jon Skeet
people
quotationmark

You need to cast the args to ToolBarItemEventArgs, at which point you can access the ToolBarButton it refers to: var toolBarArgs = (ToolBarItemEventArgs) objArgs; switch (toolBarArgs.ToolBarButton.Text) { ... } However, I would... more 1/20/2016 9:44:39 AM

people

linq join and count

I'm new to Linq and was wondering how I would go about obtaining a List of Customer Id, and a count of their transactions public class Transaction { public int TransactionId...
Jon Skeet
people
quotationmark

saj's answer will only work if every customer has a transaction. Instead, it would be better to use a group join starting with Customer, and count the result: var query = from customer in customers join transaction in... more 1/20/2016 9:11:21 AM

people

How to convert count in linq?

I have a situation where I want to count the total transaction of the customer. I can do it in a mysql query but I don't know to do it in linq sql. select c.name, count(r.custid)...
Jon Skeet
people
quotationmark

I wouldn't start with the SQL... I'd start by thinking of what you're counting, which is basically the number of receipt records in the group which matches the customer. It sounds like you want something like: var query = from customer in... more 1/20/2016 8:16:31 AM

people

Getting XML data from the string

string xml = "<ABCProperties> <Action> Yes | No | None </Action><Content> <Header> Header Text </Header><Body1> Body Paragraph 1...
Jon Skeet
people
quotationmark

You're asking for the Header element - so that's what it gives you. If you only want the text of that, you can just use: var headerText = doc.Descendants("Header").Single().Value; To find all the body tags, just use a Where clause: var... more 1/19/2016 4:21:54 PM

people

XmlDocument The prefix '' cannot be redefined from '' to 'X'

I am doing this: var xml = new XmlDocument(); xml.AppendChild(xml.CreateXmlDeclaration("1.0", Encoding.UTF8.BodyName, "yes")); var el =...
Jon Skeet
people
quotationmark

You're trying to create a Document element not in a namespace, but set the default namespace at the same time. I suspect you just want: String ns = "urn:iso:std:iso:20022:tech:xsd:" + SepaSchemaUtils.SepaSchemaToString(schema); var xml =... more 1/19/2016 4:12:57 PM

people