473,467 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Check valid particular Dictionary

Hi all,
I have to write a method that test a dictionary of this type:

Dictionary<string, Dictionary<string, string[]>>

to check if every string is not null or empty.

How can I write this?

Thanks in advance.
--
Luigi

Oct 2 '08 #1
6 3752
Do you mean every string in every string[]? If so, do you have .NET 3.5
available to you? You could use:

IEnumerable<stringallValues = outer.Values
.SelectMany(inner =inner.Values)
.SelectMany(array =array);

This yields all the string values from all the string[] arrays in turn.
If you just want to know if any are incorrect:

bool anyInvalid = outer.Values
.SelectMany(inner =inner.Values)
.SelectMany(array =array)
.Any(string.IsNullOrEmpty);

Marc
[C# MVP]
Oct 2 '08 #2
"Marc Gravell" wrote:
Do you mean every string in every string[]? If so, do you have .NET 3.5
available to you? You could use:

IEnumerable<stringallValues = outer.Values
.SelectMany(inner =inner.Values)
.SelectMany(array =array);

This yields all the string values from all the string[] arrays in turn.
If you just want to know if any are incorrect:

bool anyInvalid = outer.Values
.SelectMany(inner =inner.Values)
.SelectMany(array =array)
.Any(string.IsNullOrEmpty);
Hi Mark,
sorry, but I have C# 2.0 (forget to write it first).

Luigi
Oct 2 '08 #3
sorry, but I have C# 2.0 (forget to write it first).

Then you'll just have to do a few foreach loops, I'm afraid...

Marc
Oct 2 '08 #4
"Marc Gravell" wrote:
sorry, but I have C# 2.0 (forget to write it first).

Then you'll just have to do a few foreach loops, I'm afraid...

Marc
Have you something similar Marc?
The difficult for me is to have a Dictionary embedded in another dictionary.

L
Oct 2 '08 #5
Something like below?

Dictionary<string, Dictionary<string, string[]>outer =
new Dictionary<string, Dictionary<string, string[]>>();
foreach (KeyValuePair<string, Dictionary<string, string[]>>
outerPair in outer)
{
if (string.IsNullOrEmpty(outerPair.Key))
{
Console.WriteLine("outer key is null");
}
foreach (KeyValuePair<string, string[]innerPair in
outerPair.Value)
{
if (string.IsNullOrEmpty(innerPair.Key))
{
Console.WriteLine("inner key is null; outer key: "
+ outerPair.Key);
}
foreach (string s in innerPair.Value)
{
if (string.IsNullOrEmpty(s))
{
Console.WriteLine("value is null; outer key: "
+ outerPair.Key
+ "; inner key: " + innerPair.Key);
}
}
}
}
Oct 2 '08 #6
"Marc Gravell" wrote:
Something like below?

Dictionary<string, Dictionary<string, string[]>outer =
new Dictionary<string, Dictionary<string, string[]>>();
foreach (KeyValuePair<string, Dictionary<string, string[]>>
outerPair in outer)
{
if (string.IsNullOrEmpty(outerPair.Key))
{
Console.WriteLine("outer key is null");
}
foreach (KeyValuePair<string, string[]innerPair in
outerPair.Value)
{
if (string.IsNullOrEmpty(innerPair.Key))
{
Console.WriteLine("inner key is null; outer key: "
+ outerPair.Key);
}
foreach (string s in innerPair.Value)
{
if (string.IsNullOrEmpty(s))
{
Console.WriteLine("value is null; outer key: "
+ outerPair.Key
+ "; inner key: " + innerPair.Key);
}
}
}
}
Perfect!
Thank you so much Marc.

Luigi
Oct 2 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
3
by: Shapper | last post by:
Hello, I have an aspx.vb code with a function. In this function I need to check if a variable is a valid email address. Something like: address@domain.extension How can I do this? Thanks,
4
by: Joseph Bergevin | last post by:
Why can't I use an int for a key? Doing so evidently doesn't result in unique IDs being generated. I can convert the array into a delimited string, which works fine, but then I have a good deal of...
8
by: Alexander Walker | last post by:
Hello I am using a Dictionary to store some queues which store instances of a class that I have written I would like to be able to determine whether a particular queue already contains an...
5
by: micklee74 | last post by:
hi in my code, i use dict(a) to make to "a" into a dictionary , "a" comes from user input, so my program does not know in the first place. Then say , it becomes a = { '-A' : 'value1' , '-B' :...
3
by: Peter | last post by:
Hello! I'm trying to implement a method, that checks spelling of a text and suggests corrections. The C# program looks like: ... Word.Application spellApp = new Word.Application();...
16
by: king kikapu | last post by:
Hi to all, in statically-types languages, let's say C# for example, we use polymorphism through interfaces. So we define an interface I with method M and then a class C that implements I...
22
by: SmokeWilliams | last post by:
Hi, I am working on a Spell checker for my richtext editor. I cannot use any open source, and must develop everything myself. I need a RegExp pattern to split text into a word array. I have...
4
by: sugard | last post by:
I have another problem concerning to check if a particular date belongs in a particular range. For example I need to check whether 16th december lies between 10th December and 20th December. I have...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.