在不使用历史的情况下在数组内查找值 [英] Finding value inside array without using history

查看:68
本文介绍了在不使用历史的情况下在数组内查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储随机数的数组。如果我用零替换这个数字中的1,是否可以获得替换值而不将其存储在任何地方?



例如25-45-67-86-32-65



现在25-45-67-0-32-65



想要检索86使用数组属性。



我尝试过:



i试过相同的东西是datatable(rowdeleted等)在数组中存在与否

解决方案

如果你选择不记住它,你怎么能记住一些东西?更改后的值必须以某种方式存储在某处才能恢复,即使Windows具有该回收站。对于您的问题,您可以制作原始数组的副本,然后可以从复制的数组中检索原始数组中已更改元素的原始值,例如

 // 
//实例化源数组。
//
int [] source = new int [5];
source [0] = 1;
source [1] = 2;
source [2] = 3;
source [3] = 4;
source [4] = 5;
//
//实例化并分配副本数组。
//
int [] copy = new int [source.Length];
//
//将源复制到复制数组。
//
Array.Copy(source,copy,source.Length);

//改变一个源元素
source [3] = 0;

//为(int i = 0; i< copy.Length; i ++)
{
if(source) [i]!= copy [i])Console.WriteLine(copy [i]);
}

请参阅 Array.Copy C#演示[ ^ ]


引用:

在不使用历史记录的情况下查找数组内的值

数组中的历史概念不存在。

如果你想要这个功能,我害怕你必须创造它。


I have one array which store random numbers. If i replace 1 of this number with zero is it possible that can get replaced values without storing it anywhere?

e.g 25-45-67-86-32-65

and now 25-45-67-0-32-65

want to retrieve 86 with using array properties.

What I have tried:

i have tried same thing which is there is datatable(rowdeleted etc.) are present or not in array

解决方案

How can you remember something if you choose not to remember it? The changed value has to be stored somewhere somehow before it can be recovered, even Windows has that recycle bin. For your question, you could have made a copy of the original array, then the original value of a changed element in the original array can be retrieved from the copied array, e.g.

//
// Instantiate the source array.
//
int[] source = new int[5];
source[0] = 1;
source[1] = 2;
source[2] = 3;
source[3] = 4;
source[4] = 5;
//
// Instantiate and allocate the copy array.
//
int[] copy = new int[source.Length];
//
// Copy the source to the copy array.
//
Array.Copy(source, copy, source.Length);

// change one of the source eleement
source[3] = 0;

// Find the original value of the changed element
for(int i=0; i < copy.Length; i++)
{
    if(source[i] != copy[i]) Console.WriteLine(copy[i]);
}

See demo at Array.Copy C#[^]


Quote:

Finding value inside array without using history


The concept of history in array do not exist.
If you want this feature, I fear you will have to create it.


这篇关于在不使用历史的情况下在数组内查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆