Browsing 7239 questions and answers with Jon Skeet

How much memory is allocated for static primitive type and static reference type in Java

I have two different class with static variables. One class with static reference type variables and another class with static primitive type variables. When i calculated the size...
Jon Skeet
people
quotationmark

getObjectSize() is meant to give an approximation of the size of objects of the specified type. They aren't affected by static fields, because static fields exist on a per-type basis rather than a per-object basis. Add as many static... more 6/8/2017 8:46:03 AM

people

How to get response form Oracle using C#?

I'm new in Oracle and trying to execute the next SQL request using C# try { connection.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = connection; ...
Jon Skeet
people
quotationmark

Given that you're querying count(*), you'd be better using ExecuteScalar rather than ExecuteReader(), for one thing. Next, the result will be an integer, which is why GetString() fails. Change it to: int count = (int)... more 6/8/2017 8:44:35 AM

people

How can I convert float to int?

cube1.name = string.Format("Terrain_{0}_{1}", (int)Terrain.activeTerrain.transform.position.x + tilePositionInLocalSpace.x, ...
Jon Skeet
people
quotationmark

You've just got a precedence problem. You've got: (int) x + y which is equivalent to ((int) x) + y ... which will then promote the result of the cast back to a float in order to perform floating point addition. Just make the cast... more 6/7/2017 1:42:49 PM

people

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