为什么可以private从类中的public方法返回嵌套public类?编译器是否应该抱怨返回类型的可见性小于方法?
public final class Outer {
private static final class Configurator {
private Configurator() {
}
}
public static Configurator configure() {
return new Configurator();
}
}
Run Code Online (Sandbox Code Playgroud) 是否有一个keyword引用当前类类型类似于如何this引用当前实例?
我的目的是避免在引用静态成员或枚举时输入完整的类名,但我想用"this"之类的东西来为它提供可读性,就像我为实例成员所做的那样.原因是一些类名非常庞大并导致过度包装.
我在默认网站的虚拟目录下添加了一个ASP.NET应用程序.当我更改应用程序中的子文件夹的身份验证设置(例如通过禁用匿名身份验证)时,我找不到设置的存储位置.在子文件夹中没有创建web.config,应用程序的根web.config不受影响,Process Monitor也不记录任何文件写入.
public class MyClass
{
MyEntities db = new MyEntities();
public MyClass()
{
this.Initialise(); // Does not return immediately. Why?
}
private async void Initialise();
{
await this.db.Entities.LoadAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我更改Initialise以使用await Task.Run()来调用同步this.db.Entities.Load()然后它会按预期立即返回.
我想生成给定泛型Enum类型的基础值和名称列表.我想要原生的潜在价值(如objects).
public static ReadOnlyCollection<EnumerationMember> ListFromEnum<TEnum>()
{
Type enumType = typeof(TEnum);
if (!enumType.IsEnum)
{
throw new InvalidOperationException("TEnum is not an enum");
}
Type underlyingType = Enum.GetUnderlyingType(enumType);
TEnum[] enumValues = (TEnum[])Enum.GetValues(enumType);
return enumValues
.Select(ev => new EnumerationMember(
(???)ev,
EnumerationExtension.GetDescription(enumType, ev)))
.ToList()
.AsReadOnly();
}
public class EnumerationMember
{
public EnumerationMember(object value, string description)
{
this.Value = value;
this.Description = description;
}
public object Value { get; private set; }
public string Description { get; private set; }
}
Run Code Online (Sandbox Code Playgroud) 假设一个Activity根视图永远是一个ViewGroup?是安全的吗?我有一个Activity显示各种Fragments.我可以跳过为其创建布局XML Activity并直接将Fragments 添加到其根视图中吗?
class MyClass {
private int value;
private void someFunction()
{
// value will never be assigned anywhere else while the thread is running
this.value = 10;
// start thread that reads value
}
}
Run Code Online (Sandbox Code Playgroud)
这是否需要易失性或线程保证看到最新值?
当__weak self在我的块中使用在后台线程上运行的引用时,我是否只需要nil在开始时检查,或者__weak self在第一次nil测试通过后执行期间甚至可以变为nil ?我想从self块中访问一些ivars ,我需要在块执行时的最新值.
.net ×2
c# ×2
java ×2
android ×1
android-view ×1
asp.net ×1
async-await ×1
class ×1
enums ×1
generics ×1
iis ×1
instance ×1
ios ×1
keyword ×1
objective-c ×1
oop ×1
this ×1
types ×1
visibility ×1
volatile ×1
web-config ×1