我在我的应用程序中使用实时图表库来生成折线图。它的工作方式是这样的;
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = new ChartValues<double> { 4, 6, 5, 2 ,4 }
},
new LineSeries
{
Title = "Series 2",
Values = new ChartValues<double> { 6, 7, 3, 4 ,6 },
PointGeometry = null
},
};
Labels = new[] {"Jan", "Feb", "Mar", "Apr", "May"};
YFormatter = value => value.ToString("C");
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用数据表来获取 X 和 Y 轴的值。
DataTable dt = new DataTable();
DateTime date_1 = DateTime.Today;
DateTime date_2 = DateTime.Today.AddDays(-5);
dt …
Run Code Online (Sandbox Code Playgroud) 我使用以下方法对密码进行加盐和哈希处理
public string CreateSalt(int size)
{
var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
var buff = new byte[size];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
public string GenerateSHA256Hash(String input, String salt)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
System.Security.Cryptography.SHA256Managed sha256hashstring =
new System.Security.Cryptography.SHA256Managed();
byte[] hash = sha256hashstring.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
public void Submit1_click(object sender, EventArgs r)
{
try
{
String salt = CreateSalt(10);
String hashedpassword = GenerateSHA256Hash(password1.Text, salt);
string MyConString = "SERVER=localhost;DATABASE=mydb;UID=root;PASSWORD=abc123;";
MySqlConnection connection = new MySqlConnection(MyConString);
string cmdText = "INSERT INTO authentication(agentlogin ,password ,question …
Run Code Online (Sandbox Code Playgroud) 我已经尝试过如何从c#列表页面中的字符串中删除html标签,Regex.Replace(inputHTML, @"<[^>]+>| ", "").Trim();
但这在html视图页面中不起作用,可能是这仅适用于控制器。
这是我的动作:
public ActionResult Index()
{
string AuthRole = "1,2,3";
ApplicationUser chkuser = common.CheckIsAuthorize(AuthRole);
if (chkuser != null)
{
var data = db.Page.ToList();
return View(data);
}
else
{
return RedirectToAction("Index", "Home");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的看法:
foreach (var item in Model)
{
<tr>
<td>@i</td>
<td>@item.Title</td>
<td>@item.Message</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id })
</td>
</tr>
i++;
}
Run Code Online (Sandbox Code Playgroud)
我的清单如下所示:
我也遇到了一个问题。我能够将嵌套的 JSON 转换为 key-Value ,但现在我想将其转换回其原始的 json 格式。对于我的问题,我无法使用 C# 对象模型来执行此操作,因为我拥有的 JSON 文件是动态的,并且其结构会随着时间的推移而发生变化。所以我正在寻找我们可以通过更新的键值对序列化和反序列化 JSON 的解决方案。任何帮助将是极大的解脱。TIA。
示例 JSON 代码:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
},
{
"type": "mobile",
"number": "123 456-7890"
}
],
"children": [],
"spouse": null
Run Code Online (Sandbox Code Playgroud)
}
var obj = JObject.Parse(json);
var result = obj.Descendants()
.OfType<JProperty>()
.Select(p => new …
Run Code Online (Sandbox Code Playgroud) 给定一个向量列表,我如何才能有效地从所有在不同属性中共享其他值的成员中选择一个属性的所有最大值。
例如,对于标准Vector3,我将如何选择相对于所有其他具有相同X和Z值的成员具有最大Y值的Vector3。
我当前的工作方法是像这样遍历列表:
Vector3 current = Vector3.Zero;
List<Vector3> out = new List<Vector3>();
foreach(var member in MyList)
{
current= member;
foreach(var compare in MyList)
{
if(!predicate(current,compare))
current = compare;
}
out.Add(largest);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不是特别有效,因为它执行n次平方比较,其中n是列表的长度。
关于将其缩减为更可行的数字的任何建议,因为我打算在代码的性能关键部分中使用它。
对于X和Z值相等的谓词,Y的最大值
输入示例:
(1,1,1)
(1,2,1)
(1,4,1)
(2,3,2)
(2,5,2)
(1,4,2)
(1,2,2)
(1,1,2)
(2,5,1)
(2,4,1)
(2,9,1)
Run Code Online (Sandbox Code Playgroud)
预期产量:
(1,4,1)
(2,5,2)
(1,4,2)
(2,9,1)
Run Code Online (Sandbox Code Playgroud) 我目前正在 Unity 2018 中进行开发,并制作了一个脚本来降低角色与敌人碰撞时的生命值:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthManager : MonoBehaviour
{
public static int currentHealth;
public Slider healthBar;
void Awake()
{
healthBar = GetComponent<Slider> ();
currentHealth = 100;
}
void ReduceHealth()
{
currentHealth = currentHealth - 1;
healthBar.value = currentHealth;
}
void Update()
{
healthBar.value = currentHealth;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在敌人的脚本文件中使用上述方法时,出现错误,指出“Assets/Custom Scripts/BeetleScript.cs(46,28): error CS0122: `HealthManager.ReduceHealth()' 由于其保护而无法访问等级”
以下是敌人脚本启动正在使用的变量并调用方法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BeetleScript : MonoBehaviour
{
Animator animator;
public GameObject cucumberToDestroy; …
Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×2
asp.net-mvc ×1
cryptography ×1
dynamic ×1
json ×1
linq ×1
list ×1
mysql ×1
performance ×1
sql ×1