C
C#2y ago
Gladiator

❔ Can I use slice operator with loop index (remainder operator%)?

I want to slice an array from start to end index but if end index exceeds the array length, loop it and start from index 0 (remainder operator%)
7 Replies
sibber
sibber2y ago
but then the end index could be smaller than the start index
Gladiator
Gladiator2y ago
So? I have to use array index with remainder operator and add these elements to a list? Array with 10 elements. Start from index 8 and length 5 Index 8,9,0,1,2 For example
sibber
sibber2y ago
oh thats what you meant what if the length is 12 do items get repeated, or just returns the last 2 items? i guess the latter makes more sense
Gladiator
Gladiator2y ago
I do no know what you mean It was an example. If the length is 12 and start from index 8 with 5 length, it returns 8,9,10,11,0
sibber
sibber2y ago
not the length of the array same array of 10 elements start at index 8 with length 12 instead of 5
Gladiator
Gladiator2y ago
I said it should be looped so 8,9,0,1,2,...9 I do not know what is the difference? but this sequence length is max 10 (array element size) in my scenario
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ My ASP.NET project isn't launchingI just made templates for a Standalone Angular project and a ASP.NET 6 project but it seems like onl❔ Making properties accessible by both static and non-static methodsI had to make a static duplicate of a property, because I wanted it to be accessible by both non-sta❔ Windows Forms different controls but same event doing different code?```cs private void OnSecondsChange(object sender, EventArgs e) { textBoxUpTime.Text += $"{sender✅ What is better, in this case, Replace() or Substring()In Unity it seems that text input comes with a 'Zero Width Space Character' at the end, and that mes❔ How to pass anchor tag values to controller to render view based on selected valueHI, how do I pass the values assigned to an anchor tag to the controller so that the controller can ❔ How to force method call regardless of type?```cs public class TempBaseClass { } public class TempGenericClass<T> : TempBaseClass { public ❔ Double property with [Required] data annotation does not validateHow can I make it so that the req body has to have a DiscountPercentage field?❔ 'Type may be weakened' inspection in riderIn intelliJ there is an inspection *look at screenshot* for java. Is there an equivalent for it in r❔ Where to learn building APIs ?hey guys can anyone tell me where i can learn building APIs with C#❔ The foreign key property 'UserRole.RoleId1' was created in shadow stateI've expanded the default `IdentityUserRole` implementation for .NET identity like this: ```cs publi