小编Man*_*tov的帖子

为什么将列表转换为数组不在 c# 中引用?

.Net 中的数组是引用类型。鉴于上面的两个代码段。问题:为什么设置值变量“fixedItem”会影响第一段代码中的变量“data”,而第二段代码是不影响

第一段代码:

        var data = new List<IList<int>>();
        data.Add(new List<int>() { 1, 2, 3 });
        data.Add(new List<int>() { 3, 8, 6,5 });
        data.Add(new List<int>() { 1, 2 });
        var fixedItem = data.Last();
        fixedItem[1] = 8;
        
        //Result:
        //data = {{1,2,3}, {3,8,6,5}, {1,8}}

Run Code Online (Sandbox Code Playgroud)

第二个代码段:

        var data = new List<IList<int>>();
        data.Add(new List<int>() { 1, 2, 3 });
        data.Add(new List<int>() { 3, 8, 6,5 });
        data.Add(new List<int>() { 1, 2 });
        var fixedItem = data.Last().ToArray();
        fixedItem[1] = 8;
          
        //Result:
        //data = {{1,2,3}, {3,8,6,5}, {1,2}}
Run Code Online (Sandbox Code Playgroud)

c# arrays list

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

WPF圆形移动物体

在此输入图像描述

我正在尝试创建一个示例项目来沿 WPF 中的圆形路径移动椭圆对象。为此,我使用了以下方程:x = x0 + R * sin (a), y = y0 + R * cos (a),这里 (x0, y0) 是圆形路径的中心,R 是路径的半径路径,但我的椭圆不是沿圆移动,而是沿直线移动。 我哪里弄错了?

我的 XAML 来源:

<Window x:Class="MyWpfAppSample1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MyWpfAppSample1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterOwner">
    <Grid>
        <Button Content="Start" x:Name="btnStart" Width="100" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="100,10,0,0" Click="btnStart_Click"/>
        <Button Content="Stop" x:Name="btnStop" Width="100" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="210,10,0,0" Click="btnStop_Click"/>
        <Ellipse x:Name="myEllipse" Height="10" Width="10" Fill="Aqua" Margin="400,210,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

我的 XAML C# 代码:

public partial class MainWindow : Window
    {
        private double …
Run Code Online (Sandbox Code Playgroud)

c# wpf animation

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

标签 统计

c# ×2

animation ×1

arrays ×1

list ×1

wpf ×1