小编Iva*_*nov的帖子

从十六进制转换为字符串

我需要检查一个string位于数据包内的数据包byte.如果我使用BitConverter.ToString(),我得到字节string与破折号(fe:00-50-25-40-A5-FF).
我尝试了一些快速谷歌搜索后找到的大多数函数,但是大多数函数都有输入参数类型string,如果我用string带破折号调用它们,它会抛出异常.

我需要一个函数将十六进制(as string或as byte)转换为string表示十六进制值(fe:0x31 = 1)的函数.如果输入参数是string,则该功能应识别破折号(例如"47-61-74-65-77-61-79-53-65-72-76-65-72"),因为BitConverter无法正确转换.

c# string hex bitconverter

30
推荐指数
3
解决办法
14万
查看次数

如何在Delphi中引发异常?

我要求Delphi原生,而不是Prism(net).

这是我的代码:

raise Exception.Create('some test');
Run Code Online (Sandbox Code Playgroud)

未声明的标识符"例外".

问题出在哪里,如何抛出/引发异常?

delphi exception

26
推荐指数
4
解决办法
5万
查看次数

C#:如何在ListView中添加子项

创建项目(在键下)很简单,但如何添加子项(值)?

listView1.Columns.Add("Key");
listView1.Columns.Add("Value");
listView1.Items.Add("sdasdasdasd");
//How to add "asdasdasd" under value?
Run Code Online (Sandbox Code Playgroud)

.net c# list view winforms

25
推荐指数
3
解决办法
14万
查看次数

如何用C#解析文本文件

通过文本格式我意味着更复杂的东西.

起初我开始手动将我问这个问题的文本文件中的5000行添加到我的项目中.

文本文件有5000行,长度不同.例如:

1   1   ITEM_ETC_GOLD_01    ??(?)   xxx xxx xxx_TT_DESC 0   0   3   3   5   0   180000  3   0   1   0   0   255 1   1   0   0   0   0   0   0   0   0   0   0   -1  0   -1  0   -1  0   -1  0   -1  0   0   0   0   0   0   0   100 0   0   0   xxx item\etc\drop_ch_money_small.bsr    xxx xxx xxx 0   2   0   0   1   0   0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 …
Run Code Online (Sandbox Code Playgroud)

c# parsing text

25
推荐指数
3
解决办法
14万
查看次数

LINQ:如何声明IEnumerable [AnonymousType]?

这是我的功能:

    private IEnumerable<string> SeachItem(int[] ItemIds)
    {
        using (var reader = File.OpenText(Application.StartupPath + @"\temp\A_A.tmp"))
        {
            var myLine = from line in ReadLines(reader)
                         where line.Length > 1
                         let id = int.Parse(line.Split('\t')[1])
                         where ItemIds.Contains(id)
                         let m = Regex.Match(line, @"^\d+\t(\d+)\t.+?\t(item\\[^\t]+\.ddj)")
                         where m.Success == true
                         select new { Text = line, ItemId = id, Path = m.Groups[2].Value };
            return myLine;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我得到一个编译错误,因为"myLine"不是IEnumerable [string]而且我不知道怎么写IEnumerable [匿名]

"无法将类型'System.Collections.Generic.IEnumerable [AnonymousType#1]'隐式转换为'System.Collections.Generic.IEnumerable [string]'"

.net c# linq

24
推荐指数
4
解决办法
5万
查看次数

如何使用大脑将十六进制转换为十进制?

打开计算器做这么小的东西对我来说很烦人,我坚信这句话"你知道的越多越好!" 所以我在这里问你如何将十六进制转换为十进制.

直到那一刻我使用以下公式:

Hex:        Decimal:
12          12+6
22          22+2*6
34          34+3*6
49          49+4*6
99          99+9*6
Run Code Online (Sandbox Code Playgroud)

当我继续使用更高的数字(如C0或FB)时,我感到困惑

你正在使用的公式(大脑,不是功能)是什么?

hex

24
推荐指数
4
解决办法
6万
查看次数

如何将图像放在Bitmap的图片框中

是否可以从内存(byte[]streamBitmap)加载图片而不将其保存到磁盘?

这是我用来将byte[]数组转换为Bitmap:

unsafe
{
    fixed (byte* ptr = Misc.ConvertFromUInt32Array(image))
    {
        Bitmap bmp = new Bitmap(200, 64, 800, PixelFormat.Format32bppRgb, new IntPtr(ptr));
        bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
        bmp.MakeTransparent(Color.Black);
        bmp.Save("test.bmp");
    }
}
Run Code Online (Sandbox Code Playgroud)

而不是使用Bmp.save(),我可以把Bitmap图片框放在我的表格上吗?

c# image bitmap

23
推荐指数
2
解决办法
8万
查看次数

Int to string:无法从'method group'转换为'string'

我的表单上有一个listView.我希望在程序运行期间添加内容.

这是我使用的代码

public void FillList(string[] Name,int[] empty,int[] Population,int[] Max,int[] Check,int size)
{
    if (this.InvokeRequired)
    {
        this.Invoke((MethodInvoker)delegate
        {
            for (int i = 0; i < size; i++)
            {
                ListViewItem item = new ListViewItem(Name[i]);

                item.SubItems.Add(empty[i].ToString); //error
                item.SubItems.Add(Population[i].ToString); //error
                item.SubItems.Add(Max[i].ToString);   //error

                if (Check != 1)
                    item.SubItems.Add("No");
                else
                    item.SubItems.Add("Yes");
                listView1.Items.Add(item);
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

参数必须是字符串,我试过.ToString,但我明白了:

参数'1':无法从'方法组'转换为'字符串'

c# string int listview winforms

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

DataContext ="{Binding}"是什么意思?

我试图找出HeaderedContentControl中的项目来自一个不属于我的项目.这是代码:

        <HeaderedContentControl 
            Content="{Binding Path=Workspaces}"
            ContentTemplate="{StaticResource WorkspacesTemplate}"
            Header="Workspaces"
            Style="{StaticResource MainHCCStyle}" 
            DataContext="{Binding}" // <--- this 
       />

<DataTemplate x:Key="WorkspacesTemplate">
<TabControl 
  IsSynchronizedWithCurrentItem="True" 
  ItemsSource="{Binding}" 
  ItemTemplate="{StaticResource ClosableTabItemTemplate}"
  Margin="4"
  />
Run Code Online (Sandbox Code Playgroud)

所以让我们检查一下:

  1. ContentTemplate属性描述了项目的显示方式.
  2. WorkspacesTemplate将ItemsSource的属性设置为{Binding},这意味着它绑定到其DataContext属性(HeaderedContentControl的DataContext)
  3. 所以我看一下HeaderedContentControl的dataContext,但它被描述为"{Binding}"......

那是什么意思?

c# wpf xaml

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

@ Html.BeginForm()如何工作?

我是ASP.NET的新手,刚刚在asp.net上启动了MVC教程.我到了这里http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-methods-and-edit-view

到目前为止这么好,问题:

在我的视图中,我有以下代码(使用@model MyFirstMVC4.Models.Movie将模型设置为视图)

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Movie</legend>

        @Html.HiddenFor(model => model.ID)

        //... bla bla html input
        <p>
             <input type="submit" value="Save" />
        </p>
    </fieldset>
}
Run Code Online (Sandbox Code Playgroud)

我的MovieController

    // Shows the view
    public ActionResult Edit(int id = 0)
    {
        Movie movie = db.Movies.Find(id);
        if (movie == null)
        {
            return HttpNotFound();
        }
        return View(movie);
    }

    //
    // POST: /Movie/Edit/5

    [HttpPost] // Handles the view above
    public ActionResult Edit(Movie movie)
    {
        if (ModelState.IsValid)
        {
            db.Entry(movie).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc razor asp.net-mvc-4

20
推荐指数
2
解决办法
6万
查看次数

标签 统计

c# ×7

.net ×2

hex ×2

string ×2

winforms ×2

asp.net-mvc ×1

asp.net-mvc-4 ×1

bitconverter ×1

bitmap ×1

delphi ×1

exception ×1

image ×1

int ×1

linq ×1

list ×1

listview ×1

parsing ×1

razor ×1

text ×1

view ×1

wpf ×1

xaml ×1