使用LINQ获取内部列表的值(Getting the value of an inner list using LINQ)
我有以下简单的数据结构。 学生列表,每个学生都有一个唯一的ID。 每个学生都有一个他们注册的课程列表。课程也有唯一的ID,但将是多个学生课程列表的成员(因为每个课程由多个学生注册)。
我试图通过studentId和courseId找到特定的等级值。 我正在使用下面的linq查询。 我的linq仍然有点不稳定,并且想知道我写的查询是否正确? 它确实可以正常工作,但它可以更改为更优雅/可读吗?
class Student { int studentId; string studentName; List<Course> studentCourses; } class Course { int courseId; string courseName; int grade; } List<Student> students = new List<Student>(); //populate list. int studentGrade = students .Where(c => c.studentId == 1) .Select(c => c.studentCourses.FirstOrDefault(a => a.courseId == 1).grade) .FirstOrDefault();
I have the following simple data structure. A list of students, each with a unique ID. Each student has a list of courses they are enrolled in. Courses also have unique IDs, but will be members of multiple studentCourses lists (as each course is enrolled in by multiple students).
I'm trying to find a particular grade value, by studentId and courseId. I'm using the linq query below. I'm still a little shakey with my linq, and was wondering if the query i've written is correct? It does work correctly, but could it be changed to be more elegant/readable?
class Student { int studentId; string studentName; List<Course> studentCourses; } class Course { int courseId; string courseName; int grade; } List<Student> students = new List<Student>(); //populate list. int studentGrade = students .Where(c => c.studentId == 1) .Select(c => c.studentCourses.FirstOrDefault(a => a.courseId == 1).grade) .FirstOrDefault();
原文:https://stackoverflow.com/questions/11967321
最满意答案
对于包含箭头的LinearLayout添加2个LinearLayouts。 一个在第一个箭头之前,另一个在箭头之间。 此外,如下所示,向父LinearLayout添加权重总和:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_weightSum="100"> <LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_weight="10" android:layout_height="fill_parent"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imageView2" android:background="@drawable/arrow4" android:layout_marginLeft="68px" /> <LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_weight="10" android:layout_height="fill_parent"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imageView" android:background="@drawable/arrow2" android:layout_marginLeft="80px" /> </LinearLayout>
现在,您需要使用2个线性布局的重量值,直到找到所需的重量值。
For the LinearLayout that contains the arrows add 2 LinearLayouts. one before the 1st arrows and another one between the arrows. Also, add weight sum to the parent LinearLayout as follow:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_weightSum="100"> <LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_weight="10" android:layout_height="fill_parent"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imageView2" android:background="@drawable/arrow4" android:layout_marginLeft="68px" /> <LinearLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_weight="10" android:layout_height="fill_parent"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imageView" android:background="@drawable/arrow2" android:layout_marginLeft="80px" /> </LinearLayout>
Now, you need to play with the weight values for the 2 linear layouts until you find the desired ones.
相关问答
更多-
在你的图片标签中,你正在使用宽度但不是大小...... 尝试: Image: ... size: self.parent.size #I think you can remove the size hints since they don't add anything... stretch: True #keep this one as well :) In your Image tag you are using width but not size ... try: Image ...
-
有没有办法发布(普通的帖子与表格)而不改变屏幕位置?(Is there a way to post (common post with form) without changing screen position?)[2022-06-25]
通常你会使用Javascript / Ajax异步提交你的帖子。 但是,既然你要求“普通邮政方法”,我认为你的意思是一个正常的按钮点击帖子事件,你应该检查这个答案: ASP.NET MVC3 Razor - 在回发时保持滚动位置 Usually you'd use Javascript/Ajax to submit your post asynchronously. But since you asked for the "common post method", which I assume you me ... -
你可以用这个: Display display = getWindowManager().getDefaultDisplay(); Point sSize = new Point(); display.getSize(sSize); int width = sSize.x; int height = sSize.y; 你也可以用这个英寸: float mXDpi; float mYDpi; DisplayMetrics metrics = new DisplayMetri ...
-
youc可以使用CSS,你应该尝试使用position属性(相对/绝对)/检查这个链接和这个链接 youc can use CSS for this, you should try with position property(relative/absolute)/ Check this out link and this link
-
我现在正在努力解决类似的问题。 在我的情况下,我从命令行创建avd,例如。 avdmanager --verbose创建avd --force - 名称myEmulator - 设备“4in WVGA(Nexus S)”--package“system-images; android-23; google_apis; x86”--tag“google_apis”--abi“ x86“ ,如果我想运行新创建的avd模拟器,我输入命令'emulator -avd myEmulator(和可选参数)'。 也许这是 ...
-
您可以使用9补丁图像。 可以在不降低质量的情况下拉伸9个补丁图像。 有关详细信息,请参阅以下链接http://developer.android.com/guide/developing/tools/draw9patch.html You can use 9-patch images. A 9-patch image can be stretched without loosing quality. You may refer to the following link for more informati ...
-
如何根据屏幕大小更改背景图像,可能使用Bootstrap(How to change background image based on screen size, possibly with Bootstrap)[2023-01-09]
使用@media查询来编写窗口大小特定的CSS。 例: @media (min-width: 400px) { .element { background: #cccccc; } } @media (min-width: 500px) { .element { background: #888888; } } @media (min-width: 600px) { .element { background: #22 ... -
您在百分比中使用margin-top 。 但是,边距的百分比是相对于窗口宽度而不是窗口高度来衡量的! 请参见http://www.w3.org/TR/CSS2/box.html#value-def-margin-width 解决方案:使用另一个单位表示元素的边距,或使用其他方式将它们放置在屏幕上(例如top:5%与position:absolute结合)。 You are using margin-top in percentages. However, percentages for margins ar ...
-
您已将大小更新函数绑定到self.root,但这是一个login实例,它从未添加到小部件树中,从不执行任何操作 - 特别是,它永远不会更改大小,因此更新永远不会发生。 你应该简单地绑定到self而不是self.bind(pos=...) 。 此外,你应该使用大写字母开头你的小部件名称,因为它是一个值得关注的好的python约定,因为kv语言依赖于此来区分小部件和属性...并且你可能想要使用kv语言可能! You've bound your size update function to self.root, ...
-
根据屏幕尺寸,有没有办法改变图像的位置?(It's there any way to change the position of image according to screen size?)[2024-01-22]
对于包含箭头的LinearLayout添加2个LinearLayouts。 一个在第一个箭头之前,另一个在箭头之间。 此外,如下所示,向父LinearLayout添加权重总和:相关文章
更多- 利用Linq + Ajax 异步分页实现单个删除,批
- Python 列表(list)操作
- A Great List of Windows Tools
- hibernate 对list修改
- List的size大于0,但是取到的值为空
- 源码解读Mybatis List列表In查询实现的注意事项
- java中list、set和map 的区别(转)
- hibernate list查询 报类型转换异常
- Memcached get 获取key对应的值
- List用完后需要赋null吗
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)