foreach和map之间有区别吗? [英] Is there a difference between foreach and map?

查看:118
本文介绍了foreach和map之间有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这更多是计算机科学问题,而不是基于特定语言的问题,但是map操作和foreach操作之间有区别吗?还是它们只是同一事物的不同名称?

Ok this is more of a computer science question, than a question based on a particular language, but is there a difference between a map operation and a foreach operation? Or are they simply different names for the same thing?

推荐答案

不同.

foreach遍历列表,并对每个列表成员进行一些具有副作用的操作(例如,将每个保存到数据库中)

foreach iterates over a list and applies some operation with side effects to each list member (such as saving each one to the database for example)

map遍历一个列表,转换该列表的每个成员,并返回与转换后的成员大小相同的另一个列表(例如将字符串列表转换为大写字母)

map iterates over a list, transforms each member of that list, and returns another list of the same size with the transformed members (such as converting a list of strings to uppercase)

这篇关于foreach和map之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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