【问题标题】:What is the purpose of surrounding a variable/parameter with * (Star) symbols in C#? [closed]在 C# 中用 *(星号)符号包围变量/参数的目的是什么? [关闭]
【发布时间】:2016-06-14 17:51:28
【问题描述】:

我在Stripe.NETs documentation看到了这行代码

TokenId = *tokenId*,

还有……

StripeCard stripeCard = cardService.Create(*customerId*, myCard);

但我以前从未见过被 *(星号)符号包围的变量/参数。这有什么特别的吗?这是 .NET 的东西吗? C# 的东西?

非常感谢!

I remember * and ** are used as args and kwargs in python, and as a pointer to a var (*) or pointer to a pointer to a var (**) in C.

【问题讨论】:

  • 你自己试过看看会发生什么吗?
  • @AlexeiLevenkov 我想如果有人认为它在 C# 中的特定情况下使用,那么看到编译错误不会太有用。至少,它可能会在不安全的代码中工作(第一个星号),但这不是它在问题中所代表的。

标签: c# .net stripe-payments stripe.net


【解决方案1】:

这在 C# 中没有任何意义,所以我假设 Stripe 使用它来指示您应该将 tokenIdcustomerId 放在它们的位置。

【讨论】:

  • 不,它肯定意味着什么,它意味着它不会编译。星号不能在不安全之外使用,即使那样你也不能在变量之后使用它。
  • @Dispersia 确切地说,它们没有任何意义。表示将*tokenId**customerId* 替换为您的具体值。
  • 谢谢史蒂夫,昨天没能实际测试代码,只是好奇这是不是我以前没见过的东西。我的错。
【解决方案2】:

他们想通过在 *.

例如

var requestOptions = new StripeRequestOptions();
requestOptions.ApiKey = *optional*;              // this is not required unless you choose to pass the apikey on every service call
requestOptions.IdempotencyKey = "some string";   // this is for Idempotent Requests - https://stripe.com/docs/api?lang=curl#idempotent_requests
requestOptions.StripeConnectAccountId = "acct_*" // if you are using Stripe Connect and want to issue a request on the connected account

他们想要你可以用'option'替换一个有效值

【讨论】:

    猜你喜欢
    • 2012-01-01
    • 2017-04-29
    • 2011-04-10
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多