Browsing 7239 questions and answers with Jon Skeet

How do I calculate the estimated size of a text file when I have the amount of chars to be printed?

actually I have written a Java program that is printing a large String in a .txt file! Now I want to know how big the file will be, before it is generated. Actually I have the...
Jon Skeet
people
quotationmark

Java doesn't make this terribly easy, as far as I can see. I believe you do have to actually encode everything, but you don't need to create a big byte array... you can use a CharsetEncoder to keep encoding into a ByteBuffer in order to... more 7/10/2015 9:42:49 AM

people

How to concatinate byte array in java

What is the simple method two concatenate two byte arrays in Java? I used this function but got an error: java.lang.ArrayIndexOutOfBoundsException: 16 My function...
Jon Skeet
people
quotationmark

Firstly, your code is bound to fail if a.length + b.length > 100. You should be using a.length + b.length as the length of c. Yes, because when you've gone past a.length, you're still trying to use b[i]. Imagine a.length is 50 and... more 7/10/2015 8:48:04 AM

people

Timestamp calculated in Javascript and C# are different

I am calculating TimeStamp in javascript using following code var timestamp = new Date; that gives me result 1436504446858 contain 13 digits depend upon current time. The same...
Jon Skeet
people
quotationmark

Why the two methods gives so much of difference ? The Javascript code is giving you the number of milliseconds since the Unix epoch. The .NET code (if you'd got it right - more on that in a second) is giving you the number of ticks... more 7/10/2015 5:28:59 AM

people

C#: automatic conversion from enum to class

Consider this scenario. There is a struct Color (written by someone else) There is enum ColorCode which implements html named color codes. There's a static function that...
Jon Skeet
people
quotationmark

You could write an extension method on the enum: public static Color ToColor(this ColorCode colorCode) { ... } Then you could have: Color tmp = ColorCode.Aqua.ToColor(); It's not quite an implicit conversion, but it's as readable... more 7/9/2015 5:35:16 PM

people

How to store elements with different types of parameters

I want to store elements in a list, each elements having 4 parameters which are of different types (int, float, string). I thought of using an ArrayList but many person advised no...
Jon Skeet
people
quotationmark

An ArrayList is fine - but the element type should be something that combines the 4 values. For example: List<Person> people = new ArrayList<>(); ... class Person { private final String firstName; private final String... more 7/9/2015 4:13:49 PM

people

Method within a class won't take away value from integer argument

I've currently only been learning C# for a week so apologies for any stupid errors but I'm trying to call a method within a switch statement to take away an integer value that is...
Jon Skeet
people
quotationmark

This method: public void charAttack(int enemyHealth) { enemyHealth -= equippedWep[0].dmg; } ... is basically pointless. The statement enemyHealth -= ... only affects the parameter called enemyHealth. It won't change currEnemy.Health... more 7/9/2015 1:00:54 PM

people

Consume a c# base64 encoded file in java

I want to transfer a file from C# to a java webservice which accepts base64 strings. The problem is that when I encode the file using the c# Convert class, it produces a string...
Jon Skeet
people
quotationmark

"Signed" and "big-endian" are very different things, and I believe you're confusing yourself. Yes, bytes are signed in Java and unsigned in C# - but I strongly suspect you're getting the same actual bits in both cases... it's just that a... more 7/9/2015 12:35:01 PM

people

The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'IMS.Models.Dealer'

I know there are a lot of similar questions here, but none of them could solve my problem. When I access the URL: http://localhost:42626/dealer/edit/2 Error occurs: The...
Jon Skeet
people
quotationmark

Currently if the dealer ID can't be found, you're calling RedirectToAction, but ignoring the result and then trying to return your view with the dealer ID. I suspect you want: [HttpGet] public ActionResult Edit(int dealerId = 0) { ... more 7/9/2015 11:05:37 AM

people

"The system cannot find the file specified" error on process.Start();

I am trying to get the process respond as a string so I can use it in different place in my code, this is the solution that I have so far: const string ex1 =...
Jon Skeet
people
quotationmark

I suspect the problem is that the filename you're specifying is relative to your working directory, and you're expecting Process.Start to look there when starting the process - I don't believe it works that way when UseShellExecute is... more 7/9/2015 7:08:27 AM

people

Need only HH:MM:SS in time span string

I have a time span string as 1.21:00:00 it means 45 hours and i need it as 45:00:00 is it possible to do that in c#?
Jon Skeet
people
quotationmark

Unfortunately I don't think the TimeSpan custom formatting makes this feasible :( You could either perform the string formatting yourself... string text = (int) span.TotalHours + span.ToString(@"\:mm\:ss"); Or string text =... more 7/9/2015 6:23:02 AM

people