Browsing 15711 questions and answers with Jon Skeet

DateTime.ParseExact to NodaTime ZonedDateTime issue

I'm having an issue converting a parsed string into a correct NodaTime ZonedDateTime. The below method takes a string (allegedly in UTC) pushed by the brokers server, and returns...
Jon Skeet
people
quotationmark

I would suggest not using DateTime at all. You're using Noda Time - so go all in :) To parse text as a ZonedDateTime, you use a ZonedDateTimePattern. Here's an example: using System; using NodaTime; using NodaTime.Text; class Program { ... more 6/7/2017 8:05:05 AM

people

how to add zeros for integer variable

I'm very new to c# programming. I want to know how to add leading zeros for a integer type in c#. ex: int value = 23; I want to use it like this ; 0023 Thanks in advance
Jon Skeet
people
quotationmark

You can't. There's no such contextual information in an int. An integer is just an integer. If you're talking about formatting, you could use something like: string formatted = value.ToString("0000"); ... that will ensure there are at... more 6/7/2017 6:33:22 AM

people

C# Mysql Error Check if token Exist

Okay, so I want to check if the token exist. I do this and I get this ERROR: Unknown column 'WhatEverTokenIType' in 'where clause' Ik the token doesn't exist i just want it to...
Jon Skeet
people
quotationmark

Your SQL would be something like SELECT * FROM Tokens WHERE token = someToken - that's treating someToken as a column name, not a value. You should use parameterized SQL instead of building the SQL dynamically, e.g. // Include the... more 6/6/2017 10:07:48 PM

people

Async Thread.CurrentThread.CurrentCulture in .net 4.6

Because of the following information from microsoft, I updated my code a bit. It sounds like they updated the currentculture to something I could use. For apps that target the...
Jon Skeet
people
quotationmark

CurrentCulture and CurrentUICulture are independent properties. You're only setting CurrentCulture, and you're reporting that everywhere except for 2a, which reports CurrentUICulture. If you use the same property consistently throughout... more 6/6/2017 2:35:28 PM

people

Random number for dice (help)

import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) { Random dice = new Random(); int a[]=new int [7]; for(int i =...
Jon Skeet
people
quotationmark

Mostly, that's just hard to read code. It would be at least slightly simpler to read (IMO) as a[dice.nextInt(6) + 1]++; ... but it's easier still to understand it if you split things up: int roll = dice.nextInt(6) +... more 6/6/2017 9:56:42 AM

people

why int.TryParse cannot initialise multiple variables

I am using int.TryParse to parse to variables (saved as strings in the database) and am curious why I cannot initialise 2 variables: int min, max; using the following...
Jon Skeet
people
quotationmark

Well you're using &&, which is short-circuiting... if int.TryParse(string1, out min) returns false, the second call to int.TryParse won't be made, so max isn't definitely assigned. You could write: if (int.TryParse(string1, out... more 6/6/2017 9:25:29 AM

people

source cantain no data row while using take asp.net

currently when the records are zero i am getting the error source cantain no data row to manage that i have checked it count0 but still i am getting any idea how to solve...
Jon Skeet
people
quotationmark

As documented, CopyToDataTable() can't be called on an empty sequence of rows - presumably because then there's no schema information to include. Instead, if you know your original table is empty and you want a new table with the same... more 6/6/2017 7:14:41 AM

people

Other ways of writing \ in C#

I have a bit of code that writes to a text document and i want to do this: pathtxt.Text = pathtxt.Text + treeView1.SelectedNode.Text + "\"; but it thinks the \ is the start of...
Jon Skeet
people
quotationmark

\ is used for escape sequences in text literals for C#. The compiler doesn't think it's the start of a comment: it thinks it's the start of an escape sequence. So you either need to use "\\" (i.e. the escape sequence for backslash) or @"\"... more 6/5/2017 4:24:11 PM

people

java.lang package in java

Since java.lang package is automatically imported in all java programs by compiler, why is it necessary to write import java.lang.annotation; statement at the top of the program...
Jon Skeet
people
quotationmark

Because the java.lang.annotation package isn't the same as the java.lang package. They're simply different packages. Imagine if importing one package imported all the packages "under" it - then import java.*; would import almost... more 6/3/2017 7:55:05 AM

people

Is its possible to pass integer value as method arguments in C# console app

In my code static void Main(string[] args) { } what i want pass integer value in method args static void Main(int? args) { }
Jon Skeet
people
quotationmark

You can't - you can only accept strings. However, you can then parse those strings as integers. For example: static void Main(string[] args) { int[] intArgs = args.Select(int.Parse).ToArray(); // ... } Note that this will throw... more 6/2/2017 10:10:36 AM

people