我正在编写这段C#代码:
static void Main()
{
List<string> matches = new List<string>();
var result = Regex.Matches(myString, @"\((.*?)\)");
foreach(var x in result)
matches.Add(x.Groups[1].Value.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我很惊讶地看到它失败并显示以下错误消息:
"对象"类型不包含"组"的定义,也没有找到"对象"类型的扩展方法"组".
但是,这有效:
foreach(Match x in result)
matches.Add(x.Groups[1].Value.ToString());
Run Code Online (Sandbox Code Playgroud)
该Matches()方法返回一个MatchCollection,不应该很清楚x是一个Match?
我在这里使用Poloniex C#API:Poloniex C#.
我已通过公钥/私钥组合连接到我的Poloniex帐户
private PoloniexClient client = new PoloniexClient(Properties.Resources.PublicKey, Properties.Resources.PrivateKey);
Run Code Online (Sandbox Code Playgroud)
我有一种获取交易信息的方法
public async void GetTrades(string curr1, string curr2)
{
CurrencyPair cp = new CurrencyPair(curr1, curr2);
var trades = await client.Markets.GetTradesAsync(cp);
foreach (var x in trades)
Console.WriteLine(x);
}
Run Code Online (Sandbox Code Playgroud)
它使用API的GetTradesAsync()方法,但我得到的输出是
Jojatekok.PoloniexAPI.MarketTools.Trade
Jojatekok.PoloniexAPI.MarketTools.Trade
Jojatekok.PoloniexAPI.MarketTools.Trade
...
这是我第一次使用Poloniex(以及任何与加密货币相关的东西),所以我不确定实际结果应该是什么样子,但我确信我确实应该得到更有意义的东西.我很感激任何帮助或建议.
我有一个表格,我想通过单击按钮来隐藏或显示它。此外,当单击按钮时,应适当更改其文本。我有以下代码,但按钮的文本没有被更改:
<script>
$(document).ready(function () {
$("#myButton").click(function () {
$(".myTable").toggle(1000, "linear", function changeButtonText() {
$("#myButton").text = ($("#myButton").text === "Hide table" ? "Show table" : "Hide table");
});
});
});
</script>
...
<input type="button" id="myButton" value="Hide table" />
<table class="myTable">
...
</table>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Swagger 添加到我的 ASP.Net Core Web API 项目中,如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v0.1", new OpenApiInfo { Title = "My API", Version = "v0.1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseHttpsRedirection();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "My API V1");
});
app.UseRouting();
app.UseAuthorization();
...
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
找不到类型或命名空间名称“OpenApiInfo”
我已经安装了 Swashbuckle.AspNetCore v4.0.1,我的项目是 .Net Core 3.0。
我正在尝试将文件上传到我的 Azure 文件存储帐户。
这是我的代码:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("myConnString");
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("myFileStorage");
if (await share.ExistsAsync())
{
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("/folder1/folder2/");
CloudFile file = sampleDir.GetFileReference("fileName.jpg");
using Stream fileStream = new MemoryStream(data);
await file.UploadFromStreamAsync(fileStream);
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
指定的父路径不存在。
在这一行之后:
CloudFile file = sampleDir.GetFileReference("fileName");
Run Code Online (Sandbox Code Playgroud)
在file有这个URI:
https://myFileStorage.file.core.windows.net/myFileStorage/folder1/folder2/fileName.jpg
Run Code Online (Sandbox Code Playgroud)
即正如预期的那样。
目前我的文件存储是空的,没有文件/文件夹。如果自定义文件夹尚不存在,如何创建它们?
我已经使用Template Studio创建了UWP项目,并且正在尝试实现自定义控件。
看起来是这样的:
.xaml.cs
public sealed partial class MyButton : UserControl
{
public MyButton()
{
InitializeComponent();
}
public ImageSource Icon
{
get => (ImageSource)GetValue(s_iconProperty);
set => SetValue(s_iconProperty, value);
}
public ImageSource Pointer
{
get => (ImageSource)GetValue(s_pointerProperty);
set => SetValue(s_pointerProperty, value);
}
public static readonly DependencyProperty s_iconProperty =
DependencyProperty.Register("Icon", typeof(ImageSource), typeof(MyButton), null);
public static readonly DependencyProperty s_pointerProperty =
DependencyProperty.Register("Pointer", typeof(ImageSource), typeof(MyButton), null);
}
Run Code Online (Sandbox Code Playgroud)
.xaml
<UserControl
x:Class="...Main.Components.MyButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:...Main.Components"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" Width="755.357">
<Button Margin="0,1,1,-1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" Margin="-375,-152,-375,-148" …Run Code Online (Sandbox Code Playgroud) 我的控制器中有这段代码:
[HttpGet]
[Route("team={team}&model={model}&date={date}&distance={distance}")]
public IHttpActionResult FindVehicle([FromUri]string team = "", [FromUri]string model = "", [FromUri]DateTime? date = null, [FromUri]double distance = 0.0)
{ }
Run Code Online (Sandbox Code Playgroud)
查询字符串的所有参数都可以是可选的,这就是我使用默认值的原因。
但是,我不确定路由应该是什么,因为现在,model例如,当我不指定参数时,它在端点中的值最终是"model",而不是""。
我的代码中有以下行:
1 || printf("A");
Run Code Online (Sandbox Code Playgroud)
我很惊讶地看到A没有打印; 我猜这是由于编译器优化:1被评估为真,并且,因为整个OR表达式必须是真的,printf("A")甚至没有评估...有人可以证实这一点吗?使用不同的编译器,程序会表现得像这样吗?
我试图连接到名为“ db”的phpMyAdmin数据库,但是出现以下错误:
用户名@服务器名:〜$ mysql -u用户名-p密码
输入密码:(我输入密码)
错误1044(42000):用户'username'@'localhost'对数据库'password'的访问被拒绝
我非常确定我的用户名和密码正确,并且可以访问数据库。让我困惑的是这部分:
数据库“密码”
因为那不是我的数据库的名称。在db.php中的文件看起来是这样的:
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => 'uni_',
];
Run Code Online (Sandbox Code Playgroud)