Browsing 7239 questions and answers with Jon Skeet

Don't generate the *Count method in java protobuf

According to protobuf documentation Repeated fields have some extra methods – a Count method so something like this: // repeated .tutorial.Person.PhoneNumber phone = 4; public...
Jon Skeet
people
quotationmark

No, there's no way of doing this. If you look at the generator code (primitive fields, message fields, enum fields etc) you can see that the ...Count() methods (both interface and implementation) are written... more 1/19/2016 4:07:19 PM

people

How to filter data using ternary operator in linq

var PFOpeningList = (from emp in dbContext.EmployeeList join dsg in dbContext.hrmDesig on emp.HrmDesignationId equals dsg.Id into DsgLeftJoin ...
Jon Skeet
people
quotationmark

There's no need to use the conditional operator at all here... I suspect you want a where clause of: where opbleftjoin.CmnCalendarYearId == clndrId && (empId == 0 || emp.Id == empId) && (dptId == 0 ||... more 1/19/2016 3:04:09 PM

people

Java Tcp socket sending extra data?

I have a class that will send data in java, the server requires a certain string to actually work. I am sending the correct string, this is the connection and sending process: ...
Jon Skeet
people
quotationmark

My problem is that I don't want that to be sent, I am making sure that the string I am sending it has no extra white space at the end to create this. No, you're not. Look at your code: sendingStream.println("00 0012552 003365... more 1/18/2016 5:13:42 PM

people

load file from relative path

I am currently doing this: XDocument feedXml = XDocument.Load("C:/NewsFeed/NewsFeed/App_Data/WorldNews.xml"); But I'd like to use a relative path, so I I've tried the...
Jon Skeet
people
quotationmark

XDocument.Load doesn't know anything about mapping paths. Instead, you should use HttpServerUtility.MapPath to map the path, then pass the result into XDocument.Load: var path =... more 1/18/2016 4:57:41 PM

people

Using string interpolation and nameof in .VS 2015 NET 4.5

I'm using things like $"hello {person}" and nameof(arg1) in my code, but on checking the project properties I'm targeting .NET 4.5. Is this okay? I thought these things were...
Jon Skeet
people
quotationmark

The existing answers talk about this being a C# 6 feature without a .NET framework component. This is entirely true of nameof - but only somewhat true of string interpolation. String interpolation will use string.Format in most cases,... more 1/18/2016 4:47:41 PM

people

How to write a file comfortable and easy?

I'm pretty new in developing C#, and my problem is to write a text file. I found some solution with StreamWriter lik this... StreamWriter file = new...
Jon Skeet
people
quotationmark

The simplest approach for writing a multi-line file is File.WriteAllLines: File.WriteAllLines(@"c:\Downloads\test.txt", new[] { "this is line one", "", "", "this is line 2" }); The empty strings are there because in your original... more 1/18/2016 1:35:29 PM

people

Getting value from a database using textbox

string que = "SELECT Name FROM StudentInfo where StudentNo=textBox1.Text "; Every time I run this it always says that "The multi-part identifier "textBox1.Text" could not...
Jon Skeet
people
quotationmark

You need to make the query include the value from the textbox. SQL Server doesn't know anything about your textbox - you've just provided the text textBox1.Text as if it refers to something that SQL Server knows about. However, you... more 1/18/2016 6:58:00 AM

people

What to chose ArgumentNullException or NullReferenceException

I'm writing a small lib of method extensions. For example we have extension method public static T GetRandom<T>(this IEnumerable<T> collection) Which exception...
Jon Skeet
people
quotationmark

It's the argument which is null, so you should throw an ArgumentNullException. You should basically never throw NullReferenceException directly - it should only get thrown (automatically) when you try to dereference a null value. The fact... more 1/17/2016 5:30:14 PM

people

Convert type of anonymous object in linq or lambda expression

I have the following situation, I have a function which returns a List<object, because the object can be 2 different types Class1 or Class2, but never mixed. I use this List...
Jon Skeet
people
quotationmark

I suspect you just want: List<string> names = useFullProcess ? result.Cast<Class2>().Select(x => x.ID.ToString()).ToList() : result.Cast<Class1>().Select(x => x.Name).ToList(); You can use a cast within... more 1/15/2016 8:04:30 AM

people

IDictionary<TKey, TValue> implementation and contract for replacing values

Is there a "contract" for the interface IDictionary<TKey, TValue> I should follow when implementing value replacement with this[key] = newValue? An...
Jon Skeet
people
quotationmark

It's implementation-specific at least to some extent. For example, Dictionary<,> allows you to specify an IEqualityComparer<T> to use to check keys for equality, and SortedDictionary<,> doesn't use Equals and GetHashCode... more 1/14/2016 8:58:34 AM

people