Browsing 7239 questions and answers with Jon Skeet

How can I include a newline in a constant in C#

I have code that sends an email message to users on registration: await UserManager.SendEmailAsync(2, "Confirm your account", "Please confirm your account by...
Jon Skeet
people
quotationmark

There are three issues here. The first is that if you have a lot of text, you shouldn't be including that in the source code directly anyway. For small localizable pieces of text, you can use a resx/resources file - Visual Studio will... more 2/6/2016 8:15:00 AM

people

How to pass an Expression into a LINQ query?

I can pass an Expression into the LINQ Select() method: public IQueryable<T> GetInfo(long limit, Expression<Func<MyType, T>> selector) { return...
Jon Skeet
people
quotationmark

Well you can use: var result = (from t in DbSet where t.id < limit select t).Select(selector); ... but you can't just use the selector inside the query expression, as that's implicitly wrapping an extra... more 2/5/2016 11:41:33 AM

people

Sending Command with CR to TCP server in C#

public void ClientSend(string msg) { stream = client.GetStream(); //Gets The Stream of The Connection byte[] data; // creates a new byte without mentioning the size of it...
Jon Skeet
people
quotationmark

Basically it sounds like you need to change how you're handling the text from the RichTextBox. If you want to use \r as a line-break, use: string text = string.Join("\r", richtextbox.Lines); ClientSend(text); As mentioned in comments,... more 2/5/2016 11:39:06 AM

people

Use delegates to choose function at runtime

I am new to C# and still understanding the concept of delegates. What I know of delegates is that delegates define a function signature and functions with the same signature can...
Jon Skeet
people
quotationmark

What if i want to only call one of those methods and that decision is to be made at runtime? Then you don't combine them together, basically. For example: // Names changed to be more conventional SampleDelegate s1 = someCondition ... more 2/5/2016 10:39:02 AM

people

JDOM: cannot find symbol getAttribute()

I want to get a list of the names of keys stored in a keystore.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <keystore> <key name="key-01"> ...
Jon Skeet
people
quotationmark

Basically, you need to use generics. You're currently using raw types - so keyList.get(i) is an expression of type Object. It would also be cleaner to use an enhanced for loop (or Java 8 streams) - currently your for loop has an... more 2/5/2016 8:35:27 AM

people

Threading in C#: .join obligotory?

so i am just learning about Threads in C# and a question arose. I have a TCP-Server-Class wich accepts connections and passes them to a TCP-Client-Class. The code roughly looks...
Jon Skeet
people
quotationmark

Well, it's entirely fine to let the thread just complete normally. If the top-level call of a thread throws an exception, it may take down the process, depending on how the CLR is configured. It's usually better to have a top-level error... more 2/5/2016 7:25:40 AM

people

Multiple IF statements with similar criteria JAVA

if (currencyChosen.equals("RANDOM3") & convertTo.equals("RANDOM3")) JOptionPane.showMessageDialog(null, "SAME SENTENCE"); else if (currencyChosen.equals("RANDOM2") &...
Jon Skeet
people
quotationmark

It sounds like you probably want something like: private static final List<String> VALID_CURRENCIES = Arrays.asList("RANDOM", "RANDOM2", "RANDOM3"); ... if (currencyChosen.equals(convertTo) &&... more 2/5/2016 6:54:12 AM

people

Customeformat is not working on my datetimepicker

i have facing a problem. A datetimepicker on my windows form and i set the format properties to Custom and CustomeFormat to dd/MM/yyyy but when i run the application the...
Jon Skeet
people
quotationmark

I suspect you haven't set the Format property appropriately on the picker. From the docs for DateTimePicker.CustomFormat: The Format property must be set to DateTimePickerFormat.Custom for this property to affect the formatting of the... more 2/4/2016 9:44:08 AM

people

BufferedReader While Reading Json Data

Why do we add \n while reading JSON data with a BufferedReader? BufferedReader reader = new BufferedReader(new InputStreamReader(is)); while((line = reader.readLine())!=null){ ...
Jon Skeet
people
quotationmark

You're not adding a \n - you're putting a line break back which readLine() effectively swallowed. For example, if your text file initially consists of 5 lines: line1 line2 line3 line4 line5 then reader.readLine() will return (in... more 2/4/2016 8:46:08 AM

people

In C# When is the right time to use Apostrophe Quotation marks

I would like to know why some things have to be within a pair of Apostrophes and others within Quotation marks? void trythis(){ char myChar = 'Stuff'; String myString =...
Jon Skeet
people
quotationmark

Character literals use a single quote. So when you're dealing with char, that's 'x'. String literals use double quotes. So when you're dealing with string, that's "x". A char is a single UTF-16 code unit - in most cases "a single... more 2/4/2016 6:45:51 AM

people