The idea of C # (lambda expression, for statement) to chew

If you can't do this by making a mistake in Java testing at that time, it's not programming thinking! I remembered that I kept being told that I made it into C # and output it.

What is output to Q, 1, 2, 3

public static void Main(string[] args){
         int[] nums=new int[10];
         for(int i=0;i<nums.Length;i++){
           nums[i]=i/2; 
         }//0,0,1,1,2,2,3,3,4,4
         int sum=0;
         int index=0;
         for(;index<nums.Length;index++){
           sum+=nums[index];
           if(sum > 10){
           break;
           }
         }
         Console.WriteLine(index); //1
        
         int[] data={3,5,8,1,2};
         var result=data.Where(n=>n%2==0).Select(n=>n*n).Sum();
         Console.WriteLine(result); //2
         data.OrderByDescending(n=>n).ToList().ForEach(Console.Write); //3

Supplement 1

Difference from Java

public static void Main(string[] args){ //String in main

nums.Length //length

Way of thinking

In the first for statement, the values of the array num are added in order from index 0, and the index number when the total exceeds 10 is returned. 2 is a lambda expression, but just sum the multiplication of even numbers with the query statement as a hint. 3 is stored in a list and output in descending order by the For Each method.

Answer

Because 1 is 0,0,1,1,2,2,3,3,4,4 Answer: 7

2 is 8 * 8 = 64 2 * 2 = 4 Answer: Total of aggregates 68

3 is 85321 (no comma)

Besides, it will be Java, but let's display the diamond or the pyramid ...

Recommended Posts

The idea of C # (lambda expression, for statement) to chew
How to get the contents of Map using for statement Memorandum
The secret to the success of IntelliJ IDEA
Compare the speed of the for statement and the extended for statement.
I tried to chew C # (basic of encapsulation)
How to specify index of JavaScript for statement
The idea of quicksort
Introduction to lambda expression
The idea of jQuery
[For beginners] Quickly understand the basics of Java 8 Lambda
12 Corresponds to the while statement
A Java user over a dozen years ago tried to study the functions of Java8 (Lambda expression).
Reintroduction to Java for Humanities 0: Understanding the Act of Programming
The story of Collectors.groupingBy that I want to keep for posterity
[For beginners] Personally thinking about the cause of the error-the idea of ​​the solution
How to check for the contents of a java fixed-length string
I tried to chew C # (indexer)
I tried to chew C # (polymorphism: polymorphism)
The origin of Java lambda expressions
I want to display the number of orders for today using datetime.
The story of switching from Amazon RDS for MySQL to Amazon Aurora Serverless
The story of releasing the Android app to the Play Store for the first time.
How to switch the display of the header menu for each transition page
I tried to visualize the access of Lambda → Athena with AWS X-Ray
[Rails] Articles for beginners to organize and understand the flow of form_with
I want you to use Enum # name () for the Key of SharedPreference
Introduction to java for the first time # 2
Now let's recap the Java lambda expression
About the procedure for java to work
must not return in the for statement
How to determine the number of parallels
[Ruby] if statement concept of conditional expression
How to sort the List of SelectItem
Output of the book "Introduction to Java"
The process of introducing Vuetify to Rails
How to display the amount of disk used by Docker container for each container
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
Send a notification to slack with the free version of sentry (using lambda)
Let's refer to C ++ in the module of AndroidStudio other project (Java / kotlin)
Do you use the for statement after all? Do you use a while statement? Proper use of for statement and while statement
Conditional branching of the result of SQL statement to search only one in Java
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression