在F#,给出
type MyType = A | B | C | D | E | F | G
如何随机定义MyType实例?
我们可以像这样在顶层调用Array方法
Array(something)
Run Code Online (Sandbox Code Playgroud)
这对我来说很有意义,它是一个没有显式接收器的方法调用,而self,在这种情况下是主要的,插入在方法调用的前面.但这不等于:
Kernel.Array(something)
Run Code Online (Sandbox Code Playgroud)
这对我没有意义.由于在第一种情况下,对象main是Object类,它将Kernel模块混入,因此具有Array方法.但在第二种情况下,我们在内核模块对象本身上调用Array方法,而不是主对象,它们不是不一样吗?
对不起,我的英语不好.
我正在编写一个函数来接受Enum
并强制转换它uint
.从我在铸造时所看到的int
,你必须首先将它投射到一个物体:(int) (object) myEnumValue
.如果你写,(int) myEnumValue
你得到一个编译时异常.
现在,当我试图把它投入uint时,我期待那(uint) (object) myEnumValue
会没事的.它编译得很好,但是在运行时会生成一个InvalidCastException
.为了让它发挥作用,我已经习惯了
(uint) (int) (object) myEnumValue
Run Code Online (Sandbox Code Playgroud)
我觉得它看起来很有趣,所以我很开心,但为什么会这样呢?
也许这本来是更正确的问,为什么它是不可能投object
来uint
,但我很感兴趣,是否有另一种方式从去Enum
到uint
.在那儿?
编辑:
上下文是一个函数,如下所示:
public static uint ToUInt (Enum e)
{
return (uint) (int) (object) e;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:
最好的解决方案是thecoop提到的:
Convert.ToUInt32(e)
Run Code Online (Sandbox Code Playgroud) 根据String #intern(),intern
如果在String池中找到String,则该方法应该从String池返回String,否则将在String池中添加新的字符串对象并返回此String的引用.
所以我试过这个:
String s1 = "Rakesh";
String s2 = "Rakesh";
String s3 = "Rakesh".intern();
if ( s1 == s2 ){
System.out.println("s1 and s2 are same"); // 1.
}
if ( s1 == s3 ){
System.out.println("s1 and s3 are same" ); // 2.
}
Run Code Online (Sandbox Code Playgroud)
我期待s1 and s3 are same
将被打印为s3被实习,并且s1 and s2 are same
不会被打印.但结果是:两行都打印出来.这意味着,默认情况下,字符串常量被实现.但如果是这样,那么为什么我们需要这种intern
方法呢?换句话说,我们什么时候应该使用这种方法?
我的对象Item
有几个可以组合的二进制状态
bool CanBeSold;
bool CanBeBought;
bool CanBeExchanged;
Run Code Online (Sandbox Code Playgroud)
我需要将当前的值组合存储到一个变量中.原因是我需要将此值存储在DB中.在C++中,我会创建一个位掩码,其中一个状态占用一些位.这是.NET中的好习惯吗?
我需要将memebership超时设置为小于会话超时以避免使用成员资格并且登录会话已过期,这是我在我的asp.net应用程序中遇到的问题,我正在使用登录控制以及当用户发送评论时并且登录控制会话已过期它不应该接受评论,我后来才知道我必须在登录控制会话到期之前使会员超时到期.
那么如何才能使会员超时到期b4会话到期?
提前致谢
我正在服务器上部署我的django应用程序,在最后阶段我收到此错误:
ExtractionError at /admin/
Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/.python-eggs'
The Python egg cache directory is currently set to:
/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
Request Method: GET
Request URL: http://go-ban.org/admin/
Exception Type: ExtractionError
Exception Value:
Can't …
Run Code Online (Sandbox Code Playgroud) char
在C中使用小整数有什么不利吗?除了占用/记忆效益之外还有其他优点吗?
特别是,处理器是否可能char
更好或更差地应对整数运算(long
/ short
)int
?
我知道这将是处理器/系统/编译器特定的,但我希望在一般情况下得到答案,或者至少是32位Windows和Solaris的一般情况,我正在研究的系统.我还假设已经处理了溢出/回绕问题等问题.
更新:Visual Studio 6.0实际上没有stdint.h
Christoph建议的那样.Windows上的一些基准测试(VS 6.0,调试版本,32位)与一些堆叠循环一起提供int
并long
提供类似的性能,大约是其两倍char
.使用gcc在Linux上运行相同的测试,类似于pegs int
和long
类似,并且速度都快char
,尽管差异不太明显.
作为旁注,我没有花太多时间观察,但我发现(通过维基百科)的VS 6.0 的第一个实现stdint.h
定义为,尽管在我的测试中看起来似乎更慢.因此,正如Christoph正确地提出的那样,故事的寓意:始终是基准!uint_fast8_t
unsigned char
对于InnoDB存储,最好是计算记录总数
使用mysql_num_rows
上
select * from tbl where pk = 1
Run Code Online (Sandbox Code Playgroud)或者
获取数组并从中检索"total"值
select count(*) as total from tbl where pk = 1
Run Code Online (Sandbox Code Playgroud)?
说明我的问题的最好方法是使用此示例代码:
class Item {}
class Container< T > {}
class Program
{
static void DoSomething( object something )
{
if( typeof( Item ) == something.GetType() )
{
System.Console.WriteLine( "Item" );
}
else if( typeof( Container<> ) == something.GetType() )
{
System.Console.WriteLine( "Container<>" );
}
}
static void Main( string[] args )
{
DoSomething( new Item() );
DoSomething( new Container< int >() );
}
}
Run Code Online (Sandbox Code Playgroud)
以下行不起作用:
else if( typeof( Container<> ) == something.GetType() )
Run Code Online (Sandbox Code Playgroud)
它是一个方法,使之没有明确地改变工作Container<>
为Container<int>
?我想知道对象是'容器'类型,我真的没有兴趣是它Container<int>
还是 …