比较params对象数组(Compare params array of objects)
我正在研究一种比较对象集合的方法(因为对象支持所有类型),如果它们完全相同,它将返回true,但是如果一个或多个不同,它将返回false。
这是我拥有的:
public static bool Compare(bool compareTypes = false, params object[] values) { if (!compareTypes) { if (values is null || values.Length == 0) return false; else if (values.Length == 1) return true; else return values[0] == values[1]; } else { if (values is null || values.Length == 0) return false; else if (values.Length == 1) return true; else return values[0].GetType() == values[1].GetType(); } }
只要对象的数量是2,它就可以正常工作。
我的问题是,我希望方法比较所有参数的值或类型,而不管数量
这就是我想要的方法
Compare (false, "Hello", "Hello") //True Compare(false, "Hello", "Bye") //False Compare(true, 0, 1) //True Compare(true, "Hi", 20) //False Compare(false, "LOL", "LOL", "LOL", "LOL") //True Compare(false, "LOL", "LOL", "LOL", "lol") //False
I'm working on a method that compares a collection of objects (since the object supports all types), if they are all the same, it returns true, but if one or more differs, it returns false.
This is what I have:
public static bool Compare(bool compareTypes = false, params object[] values) { if (!compareTypes) { if (values is null || values.Length == 0) return false; else if (values.Length == 1) return true; else return values[0] == values[1]; } else { if (values is null || values.Length == 0) return false; else if (values.Length == 1) return true; else return values[0].GetType() == values[1].GetType(); } }
And it works fine as long as the number of objects is 2.
My problem is that I want the method to compare the value or the type of all parameters that are passed regardless of the amount
This is what I want my method to do
Compare (false, "Hello", "Hello") //True Compare(false, "Hello", "Bye") //False Compare(true, 0, 1) //True Compare(true, "Hi", 20) //False Compare(false, "LOL", "LOL", "LOL", "LOL") //True Compare(false, "LOL", "LOL", "LOL", "lol") //False
原文:https://stackoverflow.com/questions/49714956
最满意答案
它基本上是一个允许可更新视图的构造。 对于多表方案,INSERT只能是其中一个基础表。 View和要插入的表之间必须存在One-One关系。
您显示的查询是一个扩展相同概念的内联视图。
请阅读此处以获取更多文档
http://docs.oracle.com/cd/E17952_01/refman-5.1-en/view-updatability.html
现实生活 - 能够通过View实现这一目标,提供灵活性和轻松性。 但欢迎更多有价值的投入。
It is basically a construct allowing for updateable Views. For a multi table scenario a INSERT can only be to one of the underlying tables. There has to be a One-One relationship between the View and the table being inserted into.
The query you have shown is a inline view extending the same concept.
Read here for more documentation
http://docs.oracle.com/cd/E17952_01/refman-5.1-en/view-updatability.html
Real life - is so as to be able to do this via View gives flexibility, ease. But more valuable inputs are welcome.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
插入并返回子查询(Insert with returning a subquery)[2023-07-24]
returning子句只能返回受插入影响的数据。 而且你只能在CTE中有一个“最终”语句,而不是插入和选择。 但是您可以简单地将插入移动到第二个cte,然后在末尾有一个SELECT,它返回找到的数据 with found_group as ( SELECT * from "group" where code = 'tohubo' LIMIT 1 ), inserted as ( insert into group_users__user_groups (group ... -
不能使用子查询插入(Cant use insert with subquery)[2022-06-24]
正如我现在所看到的,Access无法匹配字段本身,这就是为什么子查询中的名称应该相同: INSERT INTO phones(a, b) select * from ( select C as a , D as b from banks) AS BB; 浪费了1个多小时才解决。 As I can see now, Access cant match fields itself , this why names in the subquery should be the same: INSERT INTO ... -
如何使用具有多个结果的子查询将值插入到表中?(How can I insert values into a table, using a subquery with more than one result?)[2023-08-06]
你要: insert into prices (group, id, price) select 7, articleId, 1.50 from article where name like 'ABC%'; 在那里你只是硬编码常量字段。 You want: insert into prices (group, id, price) select 7, articleId, 1.50 from article where name like 'ABC%'; where you jus ... -
您不能将子占位符用于子查询,但可以在子查询中使用占位符: connection.query( 'INSERT INTO foods (name,category) VALUES (?,(SELECT id FROM categories WHERE name = ?))', [ `pizza`, 'italian' ] ) You can't use placeholders for a subquery, but you can use placeh ...
-
你可以这样做: declare @t1 table (ID bigint identity(1, 1), Item nvarchar(max)) declare @t2 table (ID bigint identity(1, 1), Item nvarchar(max)) insert into @t1 select item from dbo.Split(@a,',') insert into @t2 select item from dbo.Split(@b,',') insert ...
-
使用子查询作为目标插入(Insert using a subquery as a target)[2023-02-11]
它基本上是一个允许可更新视图的构造。 对于多表方案,INSERT只能是其中一个基础表。 View和要插入的表之间必须存在One-One关系。 您显示的查询是一个扩展相同概念的内联视图。 请阅读此处以获取更多文档 http://docs.oracle.com/cd/E17952_01/refman-5.1-en/view-updatability.html 现实生活 - 能够通过View实现这一目标,提供灵活性和轻松性。 但欢迎更多有价值的投入。 It is basically a construct all ... -
Android SQLITE使用来自子查询的值插入到表中(Android SQLITE Insert into table with values coming from a subquery)[2022-07-07]
ContentValues容器的全部要点是能够安全地使用字符串,而不必将它们解释为SQL命令。 对insert()使用子查询是不可能的。 从另一个表中获取值的唯一方法是执行单独的查询; 在这种情况下, ThisIsAQuery()将是stringForQuery()或longForQuery() 。 The whole point of the ContentValues container is to be able to safely use strings without interpreting t ... -
SQL插入子查询错误(SQL insert subquery error)[2021-09-27]
如果子查询返回多行,则必须决定如何组合这些值。 以下查询假定您需要所有组合: INSERT INTO Work_Order (ID ,BRANCHID, BRANDID) select 66, branches.id, brands.id from brands cross join branches where branches.NAME = 'branch' and brands.NAME = 'brand' (我更改了where子句,以便在同一个表中查找与 ...