language-features

Using flag to identify spoken language

笑着哭i 提交于 2019-12-23 21:48:50
问题 In the webapp I am doing, I need to identify language people are speaking. I wanted to use flag to do that. But I have some problems. For example, if you speak French, you can put the French flag. But if you speak English you can put either the US or UK flag or a mix of both. Which flag to choose for Arabic language ? Saudi Arabian flag ? Algeria ? Morocco ? 回答1: I think it's usual to use fragments of the language as a kind of graphic (text, instead of flags), for example: english français

Objective-C: how to prevent abstraction leaks

三世轮回 提交于 2019-12-23 11:44:47
问题 I gather that in Objective-C I must declare instance variables as part of the interface of my class even if these variables are implementation details and have private access. In "subjective" C, I can declare a variable in my .c file and it is not visible outside of that compilation unit. I can declare it in the corresponding .h file, and then anyone who links in that compilation unit can see the variable. I wonder if there is an equivalent choice in Objective-C, or if I must indeed declare

Is There a Syntax Shortcut for Multiple Initialization in C#?

坚强是说给别人听的谎言 提交于 2019-12-23 10:06:37
问题 Is there a way to do this: valueType x = 1, y = 1, z = 1; with less characters? e.g. When I have a large amount of state to initialize to the same starting value. Thanks! 回答1: If the starting value is zero and they are members of your class (not local variables) then you don't need to explicitly initialize them to zero. Otherwise, no. Would it make sense to use arrays instead of having a large number of parameters? 回答2: You could try int x, y, z; x = y = z = 1; But I can't see how it would

What languages do date, time, and calendar operations really well? [closed]

本小妞迷上赌 提交于 2019-12-23 08:05:32
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 months ago . This is probably too much to ask, but is there any language that does a really terrific job of representing time and date operations? I'll grant straight away that it's really hard to write a truly great time library. That said, are there any widespread languages that have one?

What languages do date, time, and calendar operations really well? [closed]

浪子不回头ぞ 提交于 2019-12-23 08:05:00
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 months ago . This is probably too much to ask, but is there any language that does a really terrific job of representing time and date operations? I'll grant straight away that it's really hard to write a truly great time library. That said, are there any widespread languages that have one?

Is there a way to escape root namespace in VB?

我的梦境 提交于 2019-12-23 07:02:08
问题 namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Text.MyCustom mc = new System.Text.MyCustom(); } } } namespace System.Text { public class MyCustom { } } How do I do this in VB, while having a root namespace in the application, is this possible? Update : According to the answers I assume there ain't no way to do this. I posted a feature suggestion to Microsoft Connect: Please vote. 回答1: In VB.NET of VS 2012 this old problem is fixed. Beginning with this

is there an alternative way of calling next on python generators?

可紊 提交于 2019-12-22 11:01:12
问题 I have a generator and I would like to know if I can use it without having to worry about StopIteration , and I would like to use it without the for item in generator . I would like to use it with a while statement for example ( or other constructs ). How could I do that ? 回答1: Use this to wrap your generator: class GeneratorWrap(object): def __init__(self, generator): self.generator = generator def __iter__(self): return self def next(self): for o in self.generator: return o raise

ConditionalAttribute and other special classes

[亡魂溺海] 提交于 2019-12-22 05:41:16
问题 The ConditionalAttribute can be used to remove calls to a marked method depending on the compiler symbols defined. I'm assuming we could not create this class ourselves since the compiler must be looking for it specifically. I was wondering what other classes there are that the compiler, or language uses that we could not code ourselves. 回答1: The compiler looks for [ExtensionAttribute] to indicate extension methods (and classes containing extension methods). [DynamicAttribute] is used to

string.Format() parameters

风格不统一 提交于 2019-12-22 01:49:20
问题 How many parameters can you pass to a string.Format() method? There must be some sort of theoretical or enforced limit on it. Is it based on the limits of the params[] type or the memory usage of the app that is using it or something else entirely? 回答1: OK, I emerge from hiding... I used the following program to verify what was going on and while Marc pointed out that a string like this "{0}{1}{2}...{2147483647}" would succeed the memory limit of 2 GiB before the argument list, my findings

Can I determine who is calling a function or instantiating a class in Java? [duplicate]

旧城冷巷雨未停 提交于 2019-12-21 20:33:03
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: In Java, how do i find the caller of a method using stacktrace or reflection? I'm just curious. I was requesting that feature sometimes, but then I solved it with more code. (the calling class said its name while calling the method) 回答1: private Class getCallingClass() { return new SecurityManager() { protected Class[] getClassContext(){return super.getClassContext();} }.getClassContext()[2]; } OR public class