Browsing 7239 questions and answers with Jon Skeet

System.setProperty: Invalid Escape Sequence

Im trying to make a reference to a bin. System.setProperty("mbrola.base", "C:\Users\Name\Desktop\FreeTTS\MBrola Project"); But Im getting this error: Invalid escape...
Jon Skeet
people
quotationmark

Yes, because this isn't a valid string literal: "C:\Users\Name\Desktop\FreeTTS\MBrola Project" You need to escape the backslashes: "C:\\Users\\Name\\Desktop\\FreeTTS\\MBrola Project" The string itself will only have the single... more 4/30/2014 7:40:53 PM

people

Protobuf builder: set string field without memory allocation

Let's say I have to create and write huge amount of protobuf messages, which contain string field (different for each message). I create a protobuf.Builder and reuse it for...
Jon Skeet
people
quotationmark

If you're only interested in writing the messages out, you could go really low level and use CodedOutputStream.writeBytes. It's not how I normally prefer to use protocol buffers, but that's a different matter. Fundamentally, the problem... more 4/30/2014 5:40:15 PM

people

Is it possible to dynamically specify an extern alias in C#?

Let's say you have two DLLs which contain virtually identical code. There are only minor differences between them, but those differences are important enough that need to remain...
Jon Skeet
people
quotationmark

Options: Build against a single DLL, and then just switch DLL contents (i.e. build both DLLs with the same name, and just change which version you use) Create a single interface with two different implementations, one of which talks to... more 4/30/2014 5:28:03 PM

people

Linq using multiple variables in a query

I have the following function: - public IEnumerable<Employee> getEmployees(string department, string searchterm) { IEnumerable<Employee> query; ...
Jon Skeet
people
quotationmark

You can use: var query = from e in db.Employees where e.Date_Leave == null && (department == null || e.EmpDept == department) && (searchTerm == null || /* something using... more 4/30/2014 3:09:53 PM

people

Error 'Iterator cannot contain return statement ' when calling a method that returns using a yield

I'm hoping there's a nicer way to write this method & overloads with less code duplication. I want to return a sequence of deltas between items in a list. this method:- ...
Jon Skeet
people
quotationmark

The simplest approach is probably to split the method into two, one of which is implemented via an iterator block and one of which isn't: public static IEnumerable<decimal> CalculateDeltas(this IEnumerable<decimal> sequence, ... more 4/30/2014 2:43:39 PM

people

Avoiding SQL Injections with Parameters?

I have recently adjusted my code to avoid getting SQL injections and got helped with adding parameters but now the code is semi-foreign to me and was wondering what object...
Jon Skeet
people
quotationmark

You need the command itself - you're building it later: MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); Just move that higher, and then use: cmdDataBase.Parameters.AddWithValue(...); It's not clear why you're... more 4/30/2014 2:21:15 PM

people

Access specifier for constructors in C#

Can I have constructors with same parameter list but one private and one public or any other access specifier in C#. Thanks in advance.
Jon Skeet
people
quotationmark

No, you can't overload either constructors or methods by just varying access modifiers (or return types in the case of methods). You can only overload members if they have different signatures. more 4/30/2014 1:54:01 PM

people

Why is warning disable 429 not working to surpress unreachable code?

I am trying to suppress a warning in a very simple C# file, but it is not working and I cannot find what I am doing wrong here. Why is Visual Studio still showing "Unreachable...
Jon Skeet
people
quotationmark

I'm not sure why you're disabling 429, but you want to disable 0162 - that's the warning number you're getting: #pragma warning disable 0162 Always look for the specific warning number in the build output. (And of course, it's... more 4/30/2014 11:54:39 AM

people

Java : Map showing error : bad operand type for binary operator "+"

Below is my code. i am successfully adding values in Map but when try to get value of particular key and update it then no value getting getting error : bad operand type for...
Jon Skeet
people
quotationmark

You're not using generics (you're using a raw type instead), so the compiler has no idea what type of value is in the map - map.get(k) returns Object as far as the compiler is concerned, and there's no +(Object, int) operator. Just use... more 4/30/2014 9:42:32 AM

people

SHA256Cng in Javascript

I need to be able to produce a hash value in javascript that will match on the server. These are the sample input: string plaintext = "1398836885"; string salt =...
Jon Skeet
people
quotationmark

The hashing part is actually working fine - you're getting the same binary data in both cases - the only difference is that your output in the Javascript is in hex, rather than base64. This C# code: using System; class Test { static... more 4/30/2014 6:18:43 AM

people