如何从colors.xml文件以编程方式获取颜色值到C#代码?
这是我的colors.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<item name="row_a" type="color">#FFCCFFCC</item>
<item name="row_b" type="color">#FFFFFFCC</item>
<item name="all_text" type="color">#FF000000</item>
<item name="row_red" type="color">#FFFF4444</item>
<item name="row_orange" type="color">#FFE69900</item>
<item name="row_green" type="color">#FF739900</item>
<item name="wheat" type="color">#FFF5DEB3</item>
<integer-array name="androidcolors">
<item>@color/row_a</item>
<item>@color/row_b</item>
<item>@color/all_text</item>
<item>@color/row_red</item>
<item>@color/row_orange</item>
<item>@color/row_green</item>
<item>@color/wheat</item>
</integer-array>
</resources>
Run Code Online (Sandbox Code Playgroud)
我试过了:
Color t = (Color)Resource.Colors.wheat;
Run Code Online (Sandbox Code Playgroud)
但当然我不能用这种方式将int值转换为Color.
编辑:
正如我所建议的那样
Color t = Resources.GetColor(Resource.Color.row_a);
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
Error CS0120 An object reference is required for the non-static field,
method, or property 'Resources.GetColor(int)'
Run Code Online (Sandbox Code Playgroud) 在尝试运行此代码时:
l = 1000000
w = [1, 1]
for i in range(2, l):
w.append(w[-1] + w[-2])
Run Code Online (Sandbox Code Playgroud)
电脑挂起,蓝屏死机出现.我得到的唯一信息是关于记忆管理.问题出现在Python 2.7和3.4版本中.
代码适用于l = 100000.
有人能解释我究竟是为什么吗?我在Active Python中使用64位64位,Python 2.7.8 64位.
编辑:
这是R代码,效果很好:
len <- 1000000
fibvals <- numeric(len)
fibvals[1] <- 1
fibvals[2] <- 1
for (i in 3:len) {
fibvals[i] <- fibvals[i-1]+fibvals[i-2]
}
Run Code Online (Sandbox Code Playgroud) 目前我正在尝试将我的自定义对象连接到由Visual Studio自动生成的Application User.
Employee.cs
public class Employee
{
[Display(Name = "ID")]
[Key]
public int EmployeeID { get; set; }
[ForeignKey("ApplicationUser")]
public int ApplicationUserID { get; set; }
[Required]
[DataType(DataType.Currency)]
public decimal MonthlySalary { get; set; }
[Required]
public string Experience { get; set; }
[Required]
public string Description { get; set; }
public string PhotoURL { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
错误是:
运行所选代码生成器时出错:'无法检索Models.Tables.Employee的元数据.在模型生成期间检测到一个或多个验证错误:Parent_ApplicationUser_Target_Parent_ApplicationUser_Source ::参照约束的从属角色中的所有属性的类型必须与主体角色中的相应属性类型相同.实体"Parent"上的属性"ApplicationUserlD"的类型与引用约束"Parent_ApplicationUser"中实体"ApplicationUser"上的属性"Id"的类型不匹配.Employee ApplicationUser目标Employee ApplicationUser Source ::引用约束的从属角色中的所有属性的类型必须与主体角色中的相应属性类型相同.实体'Employee上的属性'ApplicationUserlD'的类型与引用约束'Employee_ApplicationUser中的实体'ApplicationUser'上的属性'Id'的类型不匹配.
Parent表包含相同的ApplicationUser引用Employee …