小编dee*_*see的帖子

C#中的结构

我在我的程序中使用了一个结构如下:

public struct chromo_typ
{
        public string   bits;  
        public float    fitness;

        chromo_typ(string bts, float ftns)
        {
            bits = bts;
            fitness = ftns;
        }
};
Run Code Online (Sandbox Code Playgroud)

我正在使用结构中定义的构造函数,即我的main()中的chromo_typ(string bts,float ftns).我的main()包含以下代码:

chromo_typ[] temp = new chromo_typ[VM_Placement.AlgorithmParameters.pop_size];

                    chromo_typ ct = new chromo_typ();

                    int cPop = 0;

                    //loop until we have created POP_SIZE new chromosomes
                    while (cPop < VM_Placement.AlgorithmParameters.pop_size)
                    {
                        // we are going to create the new population by grabbing members of the old population
                        // two at a time via roulette wheel selection.
                        string …
Run Code Online (Sandbox Code Playgroud)

c# struct

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

LINQ根据对象行中的整数获取10个对象

我正在尝试从数据库中选择10个用户,按字段"points"及其值排序.点数最多的用户可以在数据库中的任何位置,因此我必须检查所有点行,并选择具有最高"点"整数的行.字段的类型是可空的int.

我试过了 :

var top = (from UserInformation in dbConn.UserInformations 
           orderby UserInformation.Points.Count() descending
           select UserInformation).Take(10);
Run Code Online (Sandbox Code Playgroud)

但我不能这样做,因为.Count()无效int? (nullable),所以我很难使用,.getValueOrDefault()但它也不会让我使用那个.所以我现在有点卡住了.

c# linq asp.net

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

如何使一个类作为printf_s/sprintf_s的字符串工作?

我正在尝试创建一个类,让我们说MyClass,在以下条件下工作:

MyClass name = "everyone";   // Assigns "everyone" into a local string variable.
printf_s("Hello %s!", name); // Should output "Hello everyone!" without the quotes.
Run Code Online (Sandbox Code Playgroud)

我已经尝试重载运算符const char*()以及运算符char*()但似乎都没有做到这一点.

c c++ printf

0
推荐指数
1
解决办法
675
查看次数

Linq施放物体

我想在添加之前检查一个是否存在但是内部的转换.Any不起作用.

人是ObservableCollection对象,因为每个人都可以是不同的类(每个都有FirstLastName属性).

ObservableCollection<object> People = new ObservableCollection<object>();

foreach (cEmployee t in Group1)
{
  if (!People.Any((cEmployee)x => x.FirstLastName == t.FirstLastName) 
      People.Add(new cEmployee(t));              
}
Run Code Online (Sandbox Code Playgroud)

有解决方法吗?

c# linq

0
推荐指数
1
解决办法
124
查看次数

使数组像圆圈一样工作

我不太清楚如何做到这一点.

伪代码:

array1 = {"a","b", "c", "d", "e","f", "g","h", "i","j"} //there might be more values.
take c
loop =>c+3 =f
       f+3 =i
       i+3 =b
       b+3 =e
......
end loop
Run Code Online (Sandbox Code Playgroud)

我需要将其array1作为圆圈工作,并找到添加3(f,i,b,e等)的字母.

c#

0
推荐指数
2
解决办法
2704
查看次数

无法将类型'string'隐式转换为'int'

我不断收到调试错误"无法在C#中隐式转换类型'字符串'到'int'".

这是我的代码片段:

private void button2_Click(object sender, EventArgs e) //button to start takedown
        {
            byte[] packetData = System.Text.ASCIIEncoding.ASCII.GetBytes("<Packet OF Data Here>");
            string IP = "127.0.0.1";
            int port = "80";

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(IP), port);

            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            client.SendTo(packetData, ep);
        }
Run Code Online (Sandbox Code Playgroud)

.net c# sockets asp.net visual-studio-2010

-1
推荐指数
2
解决办法
5万
查看次数

如何使用HttpClient发送Ajax请求

我有一个网站发送Ajax请求来检查数字的验证.我希望使用HttpClient在我的WPF应用程序中发送该请求.

它使用post方法,这里是请求url:http://sim.mci.ir/chk-number-availability

这是标题:

Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 18
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _ga=GA1.2.589400539.1410935105; JSESSIONID=33719B6BDA36C7C23A96B5E73F602B08; _gat=1
Host: sim.mci.ir
Pragma: no-cache
Referer: http://sim.mci.ir/first-step
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
X-Requested-With: XMLHttpRequest
Run Code Online (Sandbox Code Playgroud)

这是唯一的价值:

number=09122175567
Run Code Online (Sandbox Code Playgroud)

我以常见方式使用SendAsync()和PostAsync()方法,但它不起作用.我认为问题出在请求标题中.

c# dotnet-httpclient

-1
推荐指数
1
解决办法
8807
查看次数

标签 统计

c# ×6

asp.net ×2

linq ×2

.net ×1

c ×1

c++ ×1

dotnet-httpclient ×1

printf ×1

sockets ×1

struct ×1

visual-studio-2010 ×1