c# - Improve Code: Compare 2 list of elements -
Sorry for the newbie question, but, I am new to programming ..
I check I do not already have more than one element in TypeA
in listOfDifferentTypes
. I have followed the code:
Public Zero check type (object param) {if (the absolute is TypeA) {int i = 0; TypeA paramToCheck = (TypeA) Ultimate; Foreign currency (different pariagag, different type in the list) {If (Parab is type A) {var paramInList = (TypeA) paramB; If (paramToCheck.ID == paramInList.ID) {i ++; }}} If (i> 1) {paramToCheck.m_Error = "Error Text"; }}}
I think this is not a very clean solution, can this code be improved / customized?
You can use LINQ for this :) It would look great:
// Check for string - Replace & lt; String & gt; With & lt; Some type & gt; Private bowl for more types on other types (list & lt; objects & gt; different types) {type different types. Type & lt; String & gt; (). Calculate ()> 1; }
Usage:
list & lt; Object & gt; List different types = new list & lt; Object & gt; {"String", 13, 52, "string", 54.3f}; Var res = moreThanOne (list different types);
I see that if you also check for any type of identity, then try it:
To do what your code is doing Updated
Updated: has been replaced. () with. (1). Some () will be closed if it is more than 1)
Private zero check-type (Object param, list & lieutenant; object & Gt; different types) {var paramToCheck = Ultimate in TypeA; If return (paramToCheck == empty); Var res = different Types.OfType & lt; TypeA & gt; (). Where (t = & gt; tid == paramToCheck.id). Skip (1). anyone (); If (res) paramToCheck.m_Error = "Error Text"; }
As I have done, you can change it:
if (the absolute typeA) {TypeA paramToCheck = (TypeA) param; ... something with
with:
as TypeA paramToCheck = param TypeA; // Return is not returned if not tyai (absolute == blank); ... do something
this is a little bit faster :)
Comments
Post a Comment