小编Ehs*_*bar的帖子

参数类型lambda表达式不能赋值给参数类型int error

我有这样的Major模型:

public int Id { get; set; }
public string MajorName{ get; set; }
public string Password { get; set; }
public System.DateTime RegisterDate { get; set; }
public string StudentId { get; set; }
public string State { get; set; }
public int FacultyId { get; set; }
public int MajorId { get; set; }
public HttpPostedFileBase ImgFile { get; set; }
Run Code Online (Sandbox Code Playgroud)

所以我在上面的模型库中有这样的方法:

public Major FindMajorById(int id)
{
    return _dbcontext.Majors.Find(id);
}
Run Code Online (Sandbox Code Playgroud)

在我看来,我通过了id,我需要专业名称:

<td>
    @{
        EducationRepositor.MajorRepository objmajor=new MajorRepository(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc lambda asp.net-mvc-3 asp.net-mvc-4

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

在c#中使用套接字编程接收消息不起作用

我正在尝试使用套接字编程编写程序.该程序只是从客户端向服务器发送消息.

客户端代码是这样的:

  class Program
    {
        static void Main(string[] args)
        {

            TcpClient client = new TcpClient();
            IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3000);
            client.Connect(serverEndPoint);
            NetworkStream clientStream = client.GetStream();
            ASCIIEncoding encoder = new ASCIIEncoding();
            byte[] buffer = encoder.GetBytes("Hello Server!");
            clientStream.Write(buffer, 0, buffer.Length);
            clientStream.Flush();
        }
    }
Run Code Online (Sandbox Code Playgroud)

您可以看到客户端只是向服务器发送Hello服务器.服务器代码是这样的:

 class Server
    {
        private TcpListener tcpListener;
        private Thread listenThread;

    public Server()
    {
        this.tcpListener = new TcpListener(IPAddress.Any, 3000);
        this.listenThread = new Thread(new ThreadStart(ListenForClients));
        this.listenThread.Start();
    }
    private void ListenForClients()
    {
        this.tcpListener.Start();

        while (true)
        {
            //blocks …
Run Code Online (Sandbox Code Playgroud)

c# sockets

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

在emgucv中应用sobel过滤器进行边缘检测

我正在尝试在我的图片上应用 Sobel 过滤器来检测边缘,如您所见:

Image<Gray, Byte> imgProcessed1;
private void Form1_Load(object sender, EventArgs e)
{



    Image<Bgr, Byte> imgProcessed=new Image<Bgr, byte>(@"C:\Users\Public\Pictures\Sample Pictures\1.jpg");

    imgProcessed1 = imgProcessed.Convert<Gray, byte>();
    Image<Gray, Single> img_final = (imgProcessed1.Sobel(1, 0, 5));
    pictureBox1.Image = img_final.ToBitmap();
}
Run Code Online (Sandbox Code Playgroud)

但结果很不寻常,我对 opencv 很陌生。

我的输出

在此处输入图片说明

我需要这个结果。

在此处输入图片说明

我只需要应用这个过滤器

在此处输入图片说明

c# c++ opencv image-processing emgucv

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

使用DrawString写垂直文本

我想使用DrawString在我的图形实例中编写一个垂直文本.

我的代码是这样的:

var graph = Graphics.FromImage(map);
Run Code Online (Sandbox Code Playgroud)

我从数据库中读到了文本及其位置:

graph.DrawString(ObjStationRepository.FindBy(i => i.Id == t.StationId).First().Description, new Font("B Nazanin", 18), Brushes.White, t.XLocation + 70, t.YLocation +80);
Run Code Online (Sandbox Code Playgroud)

但我的问题是,我需要将文本写入垂直位置而不是水平.但DrawString在水平方向写入文本!!

最好的祝福

.net c# graphics drawing

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

转换datetime的字符串格式会导致错误

我尝试转换persiandatestandard date.所以我的波斯日期有这些格式(这意味着用户可以输入以下格式:

1392/1/1
1392/01/01
1392/01/1
1392/1/01
Run Code Online (Sandbox Code Playgroud)

所以我写了一个函数将我的波斯日期转换为标准日期,如下所示:

 public DateTime ConvertPeersianToEnglish(string persianDate)
        {
            string[] formats = { "yyyy/MM/dd" };
            DateTime d1 = DateTime.ParseExact(persianDate, formats,
                                              CultureInfo.CurrentCulture, DateTimeStyles.None);
            PersianCalendar persian_date = new PersianCalendar();
            DateTime dt = persian_date.ToDateTime(d1.Year, d1.Month, d1.Day, 0, 0, 0, 0, 0);
            return dt;
        }
Run Code Online (Sandbox Code Playgroud)

但是这些功能只能处理这种格式,1392/01/01并且用户输入其他格式我得到了这个错误:

String was not recognized as a valid DateTime
Run Code Online (Sandbox Code Playgroud)

最好的祝福

c# datetime converter string-formatting

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

从ienumerable <string>中删除项目

我有一个期望的方法,IEnumerable<string>你可以在这里看到:

  public static string FromDecimalAscii(IEnumerable<string> input)
        {

            return new string(input.Select(s => (char)int.Parse(s)).ToArray());
        }
Run Code Online (Sandbox Code Playgroud)

但每次我的IEnumerable的最后一条记录都是空的,所以我在这一行得到一个错误,因为:

    return new string(input.Select(s => (char)int.Parse(s)).ToArray());
Run Code Online (Sandbox Code Playgroud)

所以我必须从我的IEnumerable.删除该项目.

错误:Input string was not in a correct format 任何想法将不胜感激.

最好的祝福

c# string ienumerable

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