小编A_S*_*_Sk的帖子

使用可选参数重载方法

我有一个类如下,有两个重载方法.

Class A
{
    public string x(string a, string b)
    {
        return "hello" + a + b;
    }

    public string x(string a, string b, string c = "bye")
    {
        return c + a + b;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我x从另一个带有两个参数的类调用该方法,那么将执行哪个方法以及为什么?即

string result = new A().x("Fname", "Lname");
Run Code Online (Sandbox Code Playgroud)

我在我的控制台应用程序中测试了这个,并且执行了2个参数的方法.有人可以解释一下吗?

c# overloading

24
推荐指数
1
解决办法
6481
查看次数

如何枚举x ^ 2 + y ^ 2 = z ^ 2 - 1(带有附加约束)

让我们N成为一个数字(10<=N<=10^5).

我必须将它分成3个数字(x,y,z),以便验证以下条件.

1. x<=y<=z 
2. x^2+y^2=z^2-1;
3. x+y+z<=N
Run Code Online (Sandbox Code Playgroud)

我必须找到一个方法中给定数字可以得到多少组合.

我尝试了如下,但它需要花费很多时间才能获得更高的数字并导致超时...

int N= Int32.Parse(Console.ReadLine());
List<String> res = new List<string>();

//x<=y<=z
int mxSqrt = N - 2;
int a = 0, b = 0;
for (int z = 1; z <= mxSqrt; z++)
{
    a = z * z;
    for (int y = 1; y <= z; y++)
    {
        b = y * y;
        for (int x = 1; x <= y; x++)
        {
            int x1 …
Run Code Online (Sandbox Code Playgroud)

c# algorithm nonlinear-functions number-theory

12
推荐指数
2
解决办法
644
查看次数

动态LINQ查询从数据库获取Field值

可能吗?

Public String Get_Filed_By_Id(string table_Name,String Field_Name,string PK_val)
{
    string strRes="";
    using(mydbcontext db=new mydbcontext())
    {
      var x=db.table_Name.Where(p=>p.Id=PK_val).FirstOrDefault().Field_Name;
      strRes=Convert.Tostring(x);
    }
 return strRes;
}
Run Code Online (Sandbox Code Playgroud)

要么

var x=(from o in db.table_Name where o.Id=PK_val select o.Field_Name).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

在这里,我正在传递Table_Name,Column_Name并且条件值(PK_val)Column_NameTable_Name某个条件(Id=Pk_val)中获取.

可能吗??

c# linq lambda dynamic-linq

7
推荐指数
1
解决办法
2360
查看次数

我的PIVOT返回每行中具有数据透视列值的重复行

我遇到了一个问题我见过其他类似问题,但这些问题的答案似乎并不适用于我的情况.这是我的第一个问题,请原谅我提前解决任何格式问题,并感谢您提供的任何见解.

#TempTBData看起来像这样:

InvoiceProductID ContactID ContactName ChargeDescription Amount
191 1832    Gloria Cheung   Cruise Fare 500.00
191 1886    John Novosad    Cruise Fare 500.00
191 2011    Christopher Yong    Cruise Fare 100.00
Run Code Online (Sandbox Code Playgroud)

我的透视代码如下所示:

SELECT DISTINCT<br>
      [InvoiceProductID]<br>
      ,[ChargeDescription]<br>
      ,[Christopher Yong],[Gloria Cheung],[John Novosad]<br>
      FROM #TempTBData<br>
          PIVOT(MAX([Amount])<br>
          FOR [ContactName] IN ([Christopher Yong],[Gloria Cheung],[John Novosad])) AS PVTTable
Run Code Online (Sandbox Code Playgroud)

..我的PIVOT结果如下:

 InvoiceProductID ChargeDescription Christopher Yong Gloria Cheung John Novosad

    191 Cruise Fare NULL    NULL    500.00
    191 Cruise Fare NULL    500.00  NULL
    191 Cruise Fare 100.00  NULL    NULL
Run Code Online (Sandbox Code Playgroud)

..我希望结果如下:

InvoiceProductID …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server pivot stored-procedures

7
推荐指数
1
解决办法
3233
查看次数

(GCP):服务器错误 服务器遇到临时错误,无法完成您的请求。请30秒后重试

我在 Google Cloud 中创建了一个“负载均衡器”,并将 2 个虚拟机连接到它。当我向“负载均衡器”发送一些请求时,有时它会传递到连接到负载均衡器的虚拟机,有时会抛出以下错误,即使当时运行状况检查 100% 正常。

错误:服务器错误 服务器遇到临时错误,无法完成您的请求。
请在 30 秒后重试。
在此输入图像描述

load-balancing google-cloud-platform google-vpc

7
推荐指数
1
解决办法
8564
查看次数

在SQL Server中包含等效的内容

当我运行此查询时:

Select * from Table1 Where Column1 Like 'aaa%' --3 Result
Select * from Table1 Where Column1 Like 'a%' --3 Result
Select * from Table1 Where Column1 Like 'A%' --3 Result
Run Code Online (Sandbox Code Playgroud)

但是当我跑步的时候

Select * from Table1 Where Contains(Column1 ,'aaa') --3 Result
Select * from Table1 Where Contains(Column1 ,'a') --0 Result
Select * from Table1 Where Contains(Column1 ,'A') --0 Result
Run Code Online (Sandbox Code Playgroud)

CONTAINS可以搜索:As Per MSDN

  1. 一个单词或短语.
  2. 单词或短语的前缀.
  3. 另一个词附近的一个词.

这是否意味着Contains无法搜索字母?

如果是,那怎么样?

EDIT2:

declare @param as varchar(20)='a'
select * from table1 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server contains sql-like

4
推荐指数
1
解决办法
9966
查看次数

读取 DataTable 时出现意外的 JSON 标记。预期的 StartArray,得到 StartObject

我有一个有效的 json(任何 json 字符串)字符串并尝试将其转换为数据集,但 Newtonsoft.Json 未能这样做。

JSON文本:

  {"root": {
  "Item": [
    {
      "Name": "Super Mario Bros",
      "Count": "14",
      "Price": "29,99",
      "Comment": "-No Comment-",
      "Artist": "N/A",
      "Publisher": "Nintendo",
      "Genre": "Video Games",
      "Year": "1985",
      "ProductID": "001"
    },
    {
      "Name": "The Legend of Zelda",
      "Count": "12",
      "Price": "34,99",
      "Comment": "-No Comment-",
      "Artist": "N/A",
      "Publisher": "Nintendo",
      "Genre": "Video Games",
      "Year": "1986",
      "ProductID": "002"
    }
  ]
}
}
Run Code Online (Sandbox Code Playgroud)

代码:

var table = JsonConvert.DeserializeObject<DataSet>(jsonText);
Run Code Online (Sandbox Code Playgroud)

错误:

读取 DataTable 时出现意外的 JSON 标记。预期的 StartArray,得到 StartObject。路径“根”,第 1 行,位置 9。

编辑1: …

c# json json.net

4
推荐指数
2
解决办法
3万
查看次数