15,905,874 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Samriddha Chowdhury (Top 13 by date)
Samriddha Chowdhury
11-Aug-23 7:40am
View
thank you so much. this one is easier for me
Samriddha Chowdhury
10-Aug-23 2:13am
View
Hi could you please explain what this piece of code is doing?
(key, items) => new
{
Price = key,
Items = items.OrderBy(m => m.MobileName).ToList(),
});
Samriddha Chowdhury
13-Jul-23 13:58pm
View
@FreedMalloc thank you sir. So it is only explicitly for understanding whether it is a class field right? No technical aspect to understand?
Samriddha Chowdhury
13-Jul-23 11:29am
View
Thank you sir. Since I am quite new so I don't feel comfortable with LINQ yet. So I am using the foreach loop solution since I understand it more easily
Samriddha Chowdhury
12-Jul-23 9:56am
View
Yes updated the tried section to elaborate the problem
Samriddha Chowdhury
12-Jul-23 3:45am
View
@Richard MacCutchan - thank you very much sir. this exactly solves my problem. Sorry for the initial confusion
Samriddha Chowdhury
12-Jul-23 2:28am
View
what I am trying to do is take an input list from the user and checking if there are any duplicates in it and then print which elements are duplicates.
So basically My List1 is the user input and List2 is the List1.Distinct() (I am trying this by hardcoding just to understand how can I extract the duplicate values)
So basically if my input list is like: {1,2,3,4,2,1,5}
Output I am expecting is {1,2} since 1,2 have duplicate values
Samriddha Chowdhury
11-Jul-23 11:04am
View
Hi now I am trying to apply this logic to the following problem : "Take 2 integer lists from user and check if any duplicates present in them". I have written the below code. When I am comparing the lists with each other then I find and print the duplicates but while checking the list itself I am unable to print the duplicates in the list itself.
static void Main(string[] args)
{
/* Inputting 1st list from user */
int x = Convert.ToInt32(Console.ReadLine());
List<int> list = new List<int>();
for (int i = 0; i < x; i++)
{
list.Add(Convert.ToInt32(Console.ReadLine()));
}
/* Inputting 2nd list from user */
int y = Convert.ToInt32(Console.ReadLine());
List<int> ints = new List<int>();
for (int i = 0; i < y; i++)
{
ints.Add(Convert.ToInt32(Console.ReadLine()));
}
/* Comparing both lists and adding duplicates in 3rd list */
List<int> r = new List<int>();
foreach (int i in list)
{
if (ints.Contains(i))
{
if (!r.Contains(i))
{
r.Add(i);
}
}
}
/* Printing message if/if not duplicates found */
/* Checking for duplicates in 1st List */
if (list.Count() != list.Distinct().Count())
{
Console.Write("Duplicates present in list 1");
List<int> temp = list.Distinct().ToList();
List<int> list2 = new List<int>(list);
foreach (int i in list)
{
list2.Remove(i);
}
//Console.WriteLine("Remove:");
foreach (int item in list2)
{
Console.Write(" "+item);
}
}
Console.WriteLine();
/* Checking for duplicates in 2nd List */
if (ints.Count() != ints.Distinct().Count())
{
Console.Write("Duplicates present in list 2");
List<int> l = (ints.Except(ints.Distinct())).ToList();
foreach (var item in l)
{
Console.Write(" " + item);
}
}
Console.WriteLine();
if (r.Count() == 0)
{
Console.WriteLine("No duplicates in comparing 2 lists");
}
else
{
Console.Write("Duplicates found: ");
foreach (var item in r)
{
Console.Write(" " + item);
}
}
Console.WriteLine();
}
Samriddha Chowdhury
11-Jul-23 10:49am
View
Please ignore my previous comment. Yes only 1 is coming up now. I didn't print the list to look at the items
Many thanks sir :)
Samriddha Chowdhury
11-Jul-23 10:46am
View
no the 1 is not coming up. empty list only
Samriddha Chowdhury
11-Jul-23 10:41am
View
yes that is correct. I have changed my code like this
List<int> list = new List<int>() { 1, 1, 2 };
List<int> list1 = new List<int>() { 1, 2 };
List<int> list2 = new List<int>(list);
foreach (int i in list1)
{
list2.Remove(i);
}
and it is also producing empty list
Could you please make the changes in my code itself?
Samriddha Chowdhury
11-Jul-23 9:44am
View
Thank you sir. Could you please help me to rectify the code so that I can get the desired output?
Samriddha Chowdhury
11-Jul-23 9:40am
View
Hi the list2 is empty and prints nothing. How to achieve the result I want? Mind you that I am very new to programming and dont have much experience
Show More