Browsing 7239 questions and answers with Jon Skeet

The Process Stream class does not support writing

I am trying to write something to a process using stream class. I am using .net 4.5. However it seems that writing is not support. Process.StandardOutput.BaseStream.CanWrite...
Jon Skeet
people
quotationmark

Yes, because it's the output of the other process. You're only able to read from it. From the documentation. Gets a stream used to read the output of the application. I know it's a bit confusing, but think of it as StandardOutput... more 7/23/2014 2:39:24 PM

people

Linq performance poor

In a for loop I run the following code: IEnumerable<KeyValuePair<DateTime, double>> avrPrefMinute = d_averagesPerMinute.Where(n => n.Key ==...
Jon Skeet
people
quotationmark

Well, it looks to me like minuteAverage.Key.Subtract(new TimeSpan(0, i, 0)) doesn't depend on anything within the loop. So extract that: var target = minuteAverage.Key.Subtract(new TimeSpan(0, i, 0)); var avrPrefMinute =... more 7/23/2014 9:12:53 AM

people

How to convert protocol buffers message to byte[]

here is my code i'm still new with this protocol buffer how can i convert the protocol buffer to byte[] so that i can encrypte for (ClientRequest req :...
Jon Skeet
people
quotationmark

Just call the toByteArray method on the message: byte[] content = clientMessage.toByteArray(); more 7/23/2014 5:48:21 AM

people

generic check for null, not for default (T)

How can i determine if value of generic method is null? So only way i found is check that it's a class and it has default value. So my code: public static string...
Jon Skeet
people
quotationmark

It sounds like you just need == null: var current = enumerator.Current; if (current == null) { sb.Append("null"); } else { sb.Append(current); } Or more compactly: var current = enumerator.Current; sb.Append(current == null ?... more 7/22/2014 2:57:26 PM

people

Why is no unchecked cast warning given when downcasting Throwable to Exception?

Using this code: public class DowncastTest { public static void main(String[] args) { try { System.out.println(1); } catch (Exception ex) { ...
Jon Skeet
people
quotationmark

Why does the javac not give an unchecked cast warning? Because there are no generics involved. I don't think "unchecked cast" means what you think it means. It's for situations like: List<?> list =... more 7/22/2014 2:55:42 PM

people

Get datetime from xml and format to yyyy,mm,dd and add as child xelement

I am trying to get the date from "forecaseDateLocalStr" and put it in the new DateTime(result). But I am getting an object error. I want to format the date and add the new xml...
Jon Skeet
people
quotationmark

Given that it looks like you're using LINQ to XML, you don't need to do any of the parsing manually. Just use the conversions to DateTime: XElement forecastDateElement = xFore.Root.Element("forecastDateLocalStr"); DateTime forecastDate =... more 7/22/2014 1:48:28 PM

people

Reference a method (for use in a lambda) with specified parameters

I have a method to validate no negative numbers in List of numbers: private void validateNoNegatives(List<String> numbers) { List<String> negatives =...
Jon Skeet
people
quotationmark

No, you can't use a method reference because you need to provide an argument, and because the startsWith method doesn't accept the value you're trying to predicate. You could write your own method, as: private static boolean... more 7/22/2014 12:21:16 PM

people

Get random seed for generating unique password

I have written a simple module which generates passwords fulfilling my complexity requirements. Module PasswordGenerator Private ReadOnly _alphaChars As Char() =...
Jon Skeet
people
quotationmark

Don't use Random at all for something as sensitive as this. Use RNGCryptoServiceProvider instead, which provides reasonably secure seeding. It's not as simple an API to use as Random - you basically just get bytes, potentially guaranteed... more 7/22/2014 11:56:03 AM

people

Better way of adding(SUM) 'List' of Arrays in C# using lambda expressions or LINQ?

List<double[]> Patterns; I am using above list to store list of patterns, here each pattern is an array of doubles ( double[] ). Using the bellow code i am adding some...
Jon Skeet
people
quotationmark

Well, you could use Enumerable.Range to iterate over all the relevant positions in the arrays, and then Sum to sum all the values for each position: // Variable names changed to follow normal C# conventions var size =... more 7/22/2014 7:25:37 AM

people

Field value of superclass is showing up as zero when referencing it from a subclass

I am currently having an issue with obtaining a value in the superclass from the subclass. In the superclass, if choice == 5, it calls the power method in the subclass. The...
Jon Skeet
people
quotationmark

You've got two instances, referred to by variables instance and instance2. These are the only lines of your code which use instance2: TrippelTylerScientificMemoryCalculator instance2 = new ... more 7/22/2014 6:05:04 AM

people