Read condition of a loop while C# [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I can't read the condition in the while ... it should start with: until the i is equal to..., and then I don't understand.
private int[] array1;
private int[] array2;
private int index;
private bool scale;
for (int i = 0; i <= 100; i++)
{
while (i == (scale ? array1[index] : array1[index]))
{
}
}
How should I read the while condition completely?
Thanks in advance.

? mean is true or false.
scale is true -> send array1[index]
scale is false -> send array2[index]

Related

Find first peak of sine wave / detect variable change c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to find at what index a sine curve (which may start at any point along the curve) reaches its first maximum, and only the first. To do this, I am running a loop which compares one value to its previous. If one point is greater than its previous value, it is trending up, and similar for the opposite.
In c#, how do you detect when the variable has changed from trending up to trending down? In other words, how do you detect when the variable has changed. In LabVIEW, this can be done using a shift register. What is the equivalent in c#?
public static int FirstMaxIndex(int[] values)
{
bool up = false;
for (int i = 1; i < values.Length; i++)
if (values[i] < values[i - 1])
{
if (up) return i;
else up = false;
}
else if (values[i] > values[i - 1])
{
up = true;
}
return -1;
}
I didn't test this. This is only to give you an idea of how to solve this. (I wrote it as close as possible to what you wrote in a comment.)

Convert Instagram Id to Url Segment [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Currently, I am trying to convert coffee script from there https://github.com/slang800/instagram-id-to-url-segment to C# but I am unable to convert because I have less exp in coffee script. What I need to do is simple but I am unable to guess the algo. If id is 1038059720608660215 then value should be 5n7dDmhTr3. The complete code of algo is available at github.
Try this
static void Main(string[] args)
{
string[] convert = {
"A","B","C","D","E","F","G","H","I","J",
"K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","a","b","c","d",
"e","f","g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x",
"y","z","0","1","2","3","4","5","6","7",
"8","9","-","_"
};
Int64 input = 1038059720608660215;
string output = "";
for (int i = 9; i >= 0; i--)
{
long digit = (input >> (6 * i)) & 0x3F;
output += convert[digit];
}
Console.WriteLine(output);
Console.ReadLine();
}

Detecting array change in linq [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Getting a byte array like this [0,0,0,0,0,1,1,1,1,3,3,3,3,0,0,0,0,0]
Does anyone know how to detect a change from 1 to 3 efficiently in linq?
Why Linq? you could achieve this with simple loop.
int previous = array[0];
for(int i=1;i< array.Length;i++)
{
if(Math.Abs(array[i]- previous) > 1) // use appropriate jump
{
//logic
}
previous = array[i];
}
If you are looking for Linq solution, you could do this.
int previous = array[0];
array.FirstOrDefault(x=>
{
var retValue = Math.Abs(x- previous) > 1;
previous = x;
return retValue;
});
If you want to find all change-indexes in the most efficient way:
List<int> changeIndexes = new List<int>();
for(int i = 1; i < array.Length; i++)
if(array[i] != array[i-1])
changeIndexes.Add(i);
Linq is not the best tool when it comes to indexes.
If you want to find only the index where 1 changes to 3 modify the condition accordingly:
if(array[i] == 3 && array[i-1] == 1) ... // break the loop if you only want to find the first

Linq query converting to bool? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How Can I get a bool back from the below linq query? I need to compare each deal target property and totalDealsCompleted property and if any deal targets are less than the total deals completed then set HasEachTeamMemberHitTarget to false.I get a an error when building the below code on the if statment. I'm doing this in c#, mvc.
for (int i = 0; i < this.Select(m => m.EmployeeID).Count(); i++)
{
if (this.Select (m => m.DealTarget < m.TotalDealsCompleted))
{
HasEachTeamMemberHitTarget = false;
break;
}
else
{
HasEachTeamMemberHitTarget = true;
}
}
Is this what you want?
HasEachTeamMemberHitTarget = this.All(m => m.DealTarget < m.TotalDealsCompleted);

Autonumber with alternating number and letters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want an auto-numbering class in c# which would generate numbers of 8 digit length in the following format i.e. 1A2B3C4D..one number followed by one letter.Any suggestions??
Pseudocode for generating such string:
String result = "";
for ( int i = 0; i < 8 ; i++)
{
if ( i % 2 == 0)
{
// random(a,b) returns random value between or equal to a-b
result.append(random(0,9).toString());
}
else
{
result.append(random(65,90).toChar()); // Generating a random value between 65-90 (A-Z in ascii)
}
}
Edit:
Or as Sayse suggested:
String result = "";
for (int i = 0; i< 4; i++)
{
result.append(random(0,9).toString());
result.append(random(65-90).toChar());
}

Categories