Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Tim Schmelter
How to return empty string if an object is null?
Here is a snippet of my code: var link = socials.Where(p => p.type == Facebook).FirstOrDefault().URL; the problem is that there aren't any social object in the list, FirstOrDefault() return null, and .URL trigger an exception. How can I avoid this in "one" line with LINQ? Thus, if null return empty "" (or custom even better) string, else .URL?
List.Any get matched String
Any determines only if there is a match, it doesn't return anything apart from the bool and it needs to execute the query.
How linq function OrderByDescending and OrderBy for string length works internally? Is it faster than doing it with loop?
The most efficient approach is to avoid LINQ here, the approach using needs only one enumeration. If you want to put the whole file into a collection anyway you could use this: Apart from that you should read about LINQ's deferred execution. Also note that your LINQ approach does not only order all lines twice to get the longest and the shortest, it also needs to read the whole file twice since is using a (as opposed to which reads all lines into an array first).
Get longest and shortest string in a esthetical way
Well, you could do this to clear your method up; public string GetLongestString(string str1, string str2) { return str1.Length > str2.Length ? str1 : str2; } public string GetShortestString(string str1, string str2) { return str1.Length > str2.Length ?
c# - What is, really, a "Special Class"? - Stack Overflow
After failing to get something like the following to compile: public class Gen<T> where T : System.Array { } with the error A constraint cannot be special class `System.Array' I started wondering, what, exactly, is a "special class"? People often seem to get the same kind of error when they specify System.Enum in a generic constraint. I got the same results with System.Object, System.Delegate, System.MulticastDelegate and System.ValueType too. Are there more of them?
c# - What exactly is a "Special Class"? - Stack Overflow
There are certain classes in the Framework which effectively pass on special characteristics to all types derived from them but do not possess those characteristics themselves. The CLR itself imposes no prohibition against using those classes as constraints, but generic types constrained to them would not acquire the non-inherited characteristics the way concrete types would.
c# - Why is "ss" equal to the german sharp-s character 'ß'? - Stack Overflow
Some background info for you. Taken from here. Windows Alt Codes In Windows, combinations of the ALT key plus a numeric code can be used to type a non-English character (accented letter or punctuation symbol) in any Windows application. More detailed instructions about typing accents with ALT keys are available. Additional options for entering accents in Windows are also listed in the Accents section of this Web site.
C# Is there a way to parse strings better?
Since a format is known, and shouldn't change Substring should work for you string data = "bsarbirthd0692"; string name, desc, date; name = data.Substring(0, 4); desc = data.Substring(4, 6); date = data.SubString(10); EDIT There's also extension methods you can create to do what ever you want.
Is there a way to parse strings better?
Since a format is known, and shouldn't change Substring should work for you string data = "bsarbirthd0692"; string name, desc, date; name = data.Substring(0, 4); desc = data.Substring(4, 6); date = data.SubString(10); EDIT There's also extension methods you can create to do what ever you want.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Tim
Contact Tim, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack