equality

Compare equality of char[] in C

别等时光非礼了梦想. 提交于 2020-01-10 03:45:08
问题 I have two variables: char charTime[] = "TIME"; char buf[] = "SOMETHINGELSE"; I want to check if these two are equal... using charTime == buf doesn't work. What should I use, and can someone explain why using == doesn't work? Would this action be different in C and C++? 回答1: char charTime[] = "TIME"; char buf[] = "SOMETHINGELSE"; C++ and C (remove std:: for C): bool equal = (std::strcmp(charTime, buf) == 0); But the true C++ way: std::string charTime = "TIME", buf = "SOMETHINGELSE"; bool

C# - Prettier way to compare one value against multiple values in a single line of code [duplicate]

*爱你&永不变心* 提交于 2020-01-07 09:38:12
问题 This question already has answers here : Multiple string comparison with C# (7 answers) Closed last year . I have this piece of code: if (filter != RECENT && filter != TODAY && filter != WEEK && filter != MONTH && filter != ALLTIME) { filter = RECENT; } Note that filter is a string and it's compared against const string types. Is there any way to do this inline and have it be more readable? Doing it with the ternary operator doesn't make it much better since I still have to repeat filter !=

How do you test functions and closures for equality?

吃可爱长大的小学妹 提交于 2020-01-07 02:04:51
问题 The book says that "functions and closures are reference types". So, how do you find out if the references are equal? == and === don't work. func a() { } let å = a let b = å === å // Could not find an overload for === that accepts the supplied arguments Here is how the Catterwauls are dealing with this: MultiClosures & Equatable Closures tests 回答1: Chris Lattner wrote on the developer forums: This is a feature we intentionally do not want to support. There are a variety of things that will

How do you test functions and closures for equality?

不羁的心 提交于 2020-01-07 02:04:14
问题 The book says that "functions and closures are reference types". So, how do you find out if the references are equal? == and === don't work. func a() { } let å = a let b = å === å // Could not find an overload for === that accepts the supplied arguments Here is how the Catterwauls are dealing with this: MultiClosures & Equatable Closures tests 回答1: Chris Lattner wrote on the developer forums: This is a feature we intentionally do not want to support. There are a variety of things that will

Warning on == used on references (Visual Studio or ReSharper)

心不动则不痛 提交于 2020-01-06 04:54:06
问题 According to the documentation of the == operator in MSDN, For reference types other than string, == returns true if its two operands refer to the same object. But, to be honest, I never check if two references are the same with == . I prefer using ReferenceEquals(obj1, obj2) and so do the default override of the Equals function. Therefore, in my projects, when the == operator is used on other types than string, equals to a bug. Is there a way to trigger a warning/error through Visual Studio

Entity Framework: Generic compare type without Id?

早过忘川 提交于 2020-01-05 04:27:07
问题 Is there anyway to do a comparison between objects for equality generically without objects having an ID? I am trying to do a typical generic update, for which I have seen many examples of online, but they all usually look something like this: public void Update(TClass entity) { TClass oldEntity = _context.Set<TClass>().Find(entity.Id); foreach (var prop in typeof(TClass).GetProperties()) { prop.SetValue(oldEntity, prop.GetValue(entity, null), null); } } or something similar.The problem with

What are the roles of IEqualityComparer and IEquatable in the Enumerable.SequenceEqual method

做~自己de王妃 提交于 2020-01-05 03:55:14
问题 On this page on MSDN they describe the SequenceEqual method of the Enumerable class. Halfway down the page it states: If you want to compare the actual data of the objects in the sequences instead of just comparing their references, you have to implement the IEqualityComparer generic interface in your class. The following code example shows how to implement this interface in a custom data type and provide GetHashCode and Equals methods. Then they show an example where they do not implement

Is there a sense of 'object equality' in Haskell?

a 夏天 提交于 2020-01-04 21:38:02
问题 If I have a singly linked list in Haskell: data LL a = Empty | Node a (LL a) deriving (Show, Eq) I can easily implement methods to insert at the end and at the beginning. But what about inserting after or before a particular element? If I have a LL of Integer , can I make a distinction in Haskell between inserting 4 after a particular node containing a 1 , rather than the first 1 that it sees when processing the list? Node 1 (Node 2 (Node 3 (Node 1 Empty))) I'm curious how an insertAfter

.net 3.5 List<T> Equality and GetHashCode

狂风中的少年 提交于 2020-01-03 18:20:23
问题 I'm implementing IEquatable in a custom class that has a List <T> as a property, like so: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public List<string> Dislikes; public bool Equals(Person p) { if (p == null) { return false; } if (object.ReferenceEquals(this, p)) { return true; } return this.FirstName == p.FirstName && this.LastName == p.LastName && this.Dislikes == p.Dislikes; //or this.Dislikes.Equals(p.Dislikes) } public override int

Congruence for heterogenous equality

时光毁灭记忆、已成空白 提交于 2020-01-03 15:18:11
问题 I'm trying to use heterogenous equality to prove statements involving this indexed datatype: data Counter : ℕ → Set where cut : (i j : ℕ) → Counter (suc i + j) I was able to write my proofs using Relation.Binary.HeterogenousEquality.≅-Reasoning , but only by assuming the following congruence property: Counter-cong : ∀ {n n′} {k : Counter n} {k′ : Counter n′} → {A : ℕ → Set} → (f : ∀{n} → Counter n → A n) → k ≅ k′ → f k ≅ f k′ Counter-cong f k≅k′ = {!!} However, I can't pattern match on k≅k′