keyword

Does C# need the private keyword?

眉间皱痕 提交于 2019-11-28 20:23:16
(inspired by this comment ) Is there ever a situation in which you need to use the private keyword? (In other words, a situation in which omitting the keyword would result in different behavior) public class Foo { public int Bar { get; private set; } } Omitting the word 'private' would change the accessibility. a situation in which omitting the keyword [ private ] would result in different behavior David Yaw's answer gave the most usual situation. Here is another one: In Account_generated.cs : // Generated file. Do not edit! public partial class Account { ... private partial class Helper { ...

When to use friend class in C++ [duplicate]

99封情书 提交于 2019-11-28 19:42:11
问题 Possible Duplicate: When should you use 'friend' in C++? I was brushing up on my C++ (I'm a Java developer) and I came across the friend class keyword which I had forgotten about for a while. Is this one of those features that's just part of the kitchen sink, or is there a good reason for doing this rather than just a vanilla getter? I understand the difference in that it limits who can access the data, but I can't think of a scenario when this would be necessary. Note: I've seen a similar

Python, why elif keyword? [closed]

老子叫甜甜 提交于 2019-11-28 19:04:32
I just started Python programming, and I'm wondering about the elif keyword. Other programming languages I've used before use else if . Does anyone have an idea why the Python developers added the additional elif keyword? Why not: if a: print("a") else if b: print("b") else: print("c") Daniel A. White Most likely it's syntactic sugar. Like the Wend of Visual Basic. Adam Lear Far as I know, it's there to avoid excessive indentation. You could write if x < 0: print 'Negative' else: if x == 0: print 'Zero' else: print 'Positive' but if x < 0: print 'Negative' elif x == 0: print 'Zero' else: print

Usage patterns for private, static, final, public, abstract keywords in java

会有一股神秘感。 提交于 2019-11-28 18:58:59
I know what all of these do except for abstract. I'm currently in the process of teaching myself java with what I consider a middle-school-level education (my highschool was in a bad neighborhood so I got shafted)... But what exactly are the usage patterns for these keywords? When do I use what? When do I omit them? Putting 'public' in front of my classes makes every class that uses it require a new file, can I just omit that if I want to create a monolithic source file? Every bit of information I look up, explains exactly WHAT these do, just doesn't give a clear view of when/why/where I

Is there a C# LINQ syntax for the Queryable.SelectMany() method?

99封情书 提交于 2019-11-28 18:30:41
When writing a query using C# LINQ syntax, is there a way to use the Queryable.SelectMany method from the keyword syntax? For string[] text = { "Albert was here", "Burke slept late", "Connor is happy" }; Using fluent methods I could query var tokens = text.SelectMany(s => s.Split(' ')); Is there a query syntax akin to var tokens = from x in text selectmany s.Split(' ') Yes, you just repeat the from ... in clause: var words = from str in text from word in str.Split(' ') select word; You can use a Compound from Clause : var tokens = from s in text from x in s.Split(' ') select x; Your query

What does “Throws” do and how is it helpful? [duplicate]

大憨熊 提交于 2019-11-28 18:27:15
This question already has an answer here: The throws keyword for exceptions in Java 4 answers I am new to Java and have just came across a tutorial which uses the"Throws" keyword in a method. I have done a little research into this but still do not really understand it. From what I have seen so far, it is telling the compiler that a certain exception may be thrown in that particular method. Why do we need to tell the compiler this? I have made many programs using merely a try-catch statement in my methods and it has worked just fine - surely it is these try-catch statements which manage

What is the difference between “keyword” and “reserved word”?

房东的猫 提交于 2019-11-28 17:44:50
What's the difference between a keyword and a reserved word ? For example, in the proposal for concepts in C++ one can read the following statement: This proposal introduces five new keywords: concept, concept map, where, axiom, and late check. All of these keywords will also be reserved words. Keywords have a special meaning in a language, and are part of the syntax. Reserved words are words that cannot be used as identifiers (variables, functions, etc.), because they are reserved by the language. In practice most keywords are reserved words and vice versa. But because they're two different

Swift `in` keyword meaning?

浪尽此生 提交于 2019-11-28 17:23:11
问题 I am trying to implement some code from parse.com and I notice a keyword in after the void. I am stumped what is this ? The second line you see the Void in PFUser.logInWithUsernameInBackground("myname", password:"mypass") { (user: PFUser?, error: NSError?) -> Void in if user != nil { // Do stuff after successful login. } else { // The login failed. Check error to see why. } } The docs don't document this. I know the in keyword is used in for loops. Anyone confirm? 回答1: In a named function, we

What's the point of “As” keyword in C#

百般思念 提交于 2019-11-28 16:57:37
From the docs: The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form: expression as type is equivalent to: expression is type ? (type)expression : (type) null except that expression is evaluated only once. So why wouldn't you choose to either do it one way or the other. Why have two systems of casting? Eric Lippert They aren't two system of casting. The two have similar actions but very different meanings. An "as" means "I think this object might actually be of this other type; give me null if

Why does Clojure have “keywords” in addition to “symbols”?

只愿长相守 提交于 2019-11-28 15:13:03
I have a passing knowledge of other Lisps (particularly Scheme) from way back. Recently I've been reading about Clojure . I see that it has both "symbols" and "keywords". Symbols I'm familiar with, but not with keywords. Do other Lisps have keywords? How are keywords different from symbols other than having different notation (ie: colons)? Brian Carper Here's the Clojure documentation for Keywords and Symbols. Keywords are symbolic identifiers that evaluate to themselves. They provide very fast equality tests... Symbols are identifiers that are normally used to refer to something else. They