我被指派将一个VB.NET项目转换为C#,我被困住了。我正在使用一个名为RsiOPCAuto的类,但我不认为我需要详细解释它是如何工作的。让我们继续处理我的问题吧。
因此,我所做的基本工作是使用以下代码从类中获取一个对象:
public partial class FrmPartialMain : Form
{
RsiOPCAuto.OPCServer oOpcServer;
public FrmPartialMain()
{
InitializeComponent();
object RsiOPCAuto;
object
enum class pid
{
Alpha, Beta, Gamma
};
int main()
{
int propId = 2;
switch(propId)
{
case pid::Alpha:
case pid::Beta:
case pid::Gamma:
break;
}
}
上面的代码片段在msvc2012中编译得很好(并且可以工作),但是在clang-3.4和g++-4.8中失败。这些都要求在交换机子句中使用static_cast<pid>(propId)。
顺便说一句,没有显式强制
我有以下课程:
enum class EnumClass : int
{
A = 0, B
};
现在,我想将枚举类型下标到一个数组中:
MyObject arr[2];
.
.
.
MyObject a = arr[EnumClass::A]
MyObject b = arr[EnumClass::B]
不幸的是,我收到了以下错误消息:
array subscript is not an integer
由于枚举类是强类型的,所以我希望它能够工作。
这是我的密码:
public class Program
{
public enum SexEnum{
Male,
Female
}
public static void Test(SexEnum s){
Console.WriteLine("enum...");
}
public static void Test(Object s){
Console.WriteLine("object...");
}
public static v
目前我正在试用Visual Studio11测试版。我使用强类型枚举来描述一些标志
enum class A : uint32_t
{
VAL1 = 1 << 0,
VAL2 = 1 << 1,
};
uint32_t v = A::VAL1 | A::VAL2; // Fails
当我尝试像上面那样组合它们时,我得到了以下错误
error C2676: binary '|' : 'A' does not define this operator or a conversion to a type acceptabl
因为c++底层类型的c++枚举应该是int。
但是有代码
enum class Properties{ first , second }
void tmp ( int i ) {}
tmp( Properties::first )
编译器抱怨Properties::首先不是int,而是Properties类型。
为了传递枚举的值给函数,我真的必须将它转换为int吗?还是有解决办法?
谢谢你帮忙。
我引用了的一个例子,如下所示
using System;
using System.Collections;
public class Person
{
public Person(string fName, string lName)
{
this.firstName = fName;
this.lastName = lName;
}
public string firstName;
public string lastName;
}
public class People : IEnumerable
{
我想将C++11作用域枚举与默认的int实现一起使用:
enum class Color
{
gray = 1,
red = 2
};
这是用gcc编译的,但是:
Color color = Color::red; // 'Color' is not a class or a namespace
Color color = red; // 'red' was not declared in this scope
我做错了什么?
编辑:
这应该是可编译的,但它不是,至少对我来说不是。我使用
我想将一个旧风格的enum更改为enum class : int,因为它有自己的范围。
但是编译器抱怨在整数算法中使用这些值。但是为什么-既然枚举被显式地键入为int?
示例:
enum class MsgType : int {
Output = 1,
Input = 2,
Debug = 3
};
enum class MsgSender : int {
A = 1,
B = 2,
C = 3
};
// later in code
int id = (MsgType::Input << 16) +
如何获得强类型的Id..。
public sealed class FileUploadId
{
public int Value { get; }
public FileUploadId(int value)
{
Value = value;
}
}
...which在我的FileUpload类中使用..。
public class FileUpload : EntityBase, IAggregateRoot
{
private FileUpload() { /* Required by EF */ }
public Fi
我只是尝试从时代初始化一个NSDate对象。我有一个Dictionary<String, AnyObject>类型的字典对象,并且我知道这个键对应于一个Int
但是Swift编译器抱怨NSDate行有一个Extra argument 'timeIntervalSince1970' in call
if let respondedDate : Int = (responseDict["expiry_date"] as AnyObject) as? Int {
let expiryDate = NSDate(timeIntervalSince
在switch语句中使用强类型枚举时,有没有办法避免显式强制转换为int
/// @desc an enumeration of the states that the session can be in.
enum class State
{
Created,
Connected,
Active,
Closed
};
State sesState = session->GetState();
switch (static_cast<int>(sesState))
{
case static_cast<int>
我今天偶然发现了一件奇怪的事:
问题5.
守则:
using System;
class Test
{
enum Foo
{
Bar,
Baz
};
const int One = 1;
const int Une = 1;
static void Main()
{
Foo f = One - Une;
Console.WriteLine(f);
}
}
现在根据上关于问题5的答案
..。这是一个已知的错误,因为一些优化太早,收集常数为0,并认为任何已知的0
示例代码:
public enum Foods
{
Burger,
Pizza,
Cake
}
private void button1_Click(object sender, EventArgs e)
{
Eat(0); // A
Eat((Foods)0); // B
//Eat(1); // C : won't compile : cannot convert from 'int' to 'Foods'
enum class test : bool { yes=true, no=false };
template< bool ok >
class A {
};
int main(){
A<test::yes> a;
}
编译失败的原因是什么?(g++ 4.7)由于C++11枚举是强类型的,所以我们应该能够使用布尔枚举作为模板类型的布尔参数?
在使用属性索引器(C#)时,我发现了一个奇怪的行为。
考虑以下程序:
public class Program
{
public static void Main(string[] args)
{
CustomMessageList cml = new CustomMessageList
{
new CustomMessage(), // Type1
new CustomMessage(), // Type1
new CustomMessage(), // Type1
我有一个由另一个控件动态创建的自定义控件,我希望根据父控件的VisualState来更改它的VisualState。VisualState是一个接受枚举数的DependencyProperty,控件内部使用它在OnPropertyChange事件中更改大小和内部布局。属性在两个控件上都是相同的(当然,类型除外)。
public ControlSize VisualState
{
get { return (ControlSize)GetValue(VisualStateProperty); }
set
{
if (value != VisualState
我正在学习Haskell。我已经创建了一个函数,它在基数'b‘中返回最大为'n’的乘法表。数字被填充到“w”数字。作为最后一步,我想自动计算“w”。为什么这个不能编译?
-- Number of digits needed for the multiplication table n*n in base 'base'
nOfDg :: Int -> Int-> Int
nOfDg n base = 1 + floor ( logBase base (n*n))
错误:
No instance for (Floating Int)
ari
public class objArrayPractice {
public static void main(String[] args) {
Object ar []= new Object [4];
ar[0]= 12;
}
}
当我编写ar= 12时,我得到的错误是:“类型不匹配:不能从int转换为对象”
我有一个执行sql任务,它将sql任务的结果分配给具有结果集的许多变量。只有当我对变量的类型使用对象类型时,它才能工作。然后,我希望使用这些变量设置带有expression.By的约束,ssis不允许这些操作的对象类型变量。有什么办法解决这个问题吗?下面是我的sql语句:
SELECT (SELECT COUNT(*) as s5 from random_table where rownum < 100) as S5,
(SELECT COUNT(*) as s6 from random_Table_2 where rownum < 100) as s6 from dual
谢谢
我正在添加一个参数,使用MySQL存储过程调用,如下所示
List<MySqlParameter> MyParams = new List<MySqlParameter>();
MyParams.Add(new MySqlParameter("MyId", 0));
但是,由于某种原因,当我在遍历代码时看到MyParams,MyId值时,它会被转换为null。有人知道为什么会这样吗?因为如果我将int变量的值赋值,如下面所示,就可以了。
int id = 0;
List<MySqlParameter> MyParams = new L
有谁能解释一下,为什么
#include <iostream>
#include <type_traits>
using namespace std;
enum E : signed int { a=-1, b = 1,};
int main() {
std::cout << std::boolalpha;
cout << "strong typed enum E:int should be signed, but is_signed returns "
<< is_signed<E&g