|
Is there a better way to code the second foreach...?
bool blnAccepted = false;
IList<Country> ftList = svc.GetCountryList;
IList<County> CountyList = svc.GetCountyList;
foreach (Country c in ftList)
{
blnAccepted = false;
foreach (County ic in CountyList)
{
if (ic.County == c.County)
{
blnAccepted = true;
break;
}
}
if (blnAccepted)
{
}
}
|
|
|
|
|
Yes, I would imagine that creating a map of countries to counties would allow you to do a single lookup. I'm not sure I follow your overall logic, but if you're doing this second loop a lot, a lookup in a hashtable will make it quicker. That's assuming you need to lookup a county for a country. If you just want to see if it exists, then keep a sorted list, so you can perform a search on it, faster than looking through the whole list.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Use Contains method in of the list.
|
|
|
|
|
If you are using C# 3.X and above, you can use the extension methods of IEnumerable<t>; the one you are looking for is Intersect. So ftList.Intersect(CountyList) gives you a collection of all elements of ftList that are present in CountyList. Hope that helps!
|
|
|
|
|
How does this work for different classes? I simplified the code earlier, so this is what I have:
Table Def:
Locations: ID, Description, TypeID, ParentID
LocationType: TypeID, Description
Rows in Location:
1 England 1 0
2 France 1 0
3 London 2 1
4 Hampshire 2 1
5 Dorest 2 1
6 Portsmouth 3 4
6 Paris 2 2
etc....
Rows in LocationType:
1 Country
2 Regions
3 Cities
4 Hospitals
5 Hotels
I now have a hierarchy of locations, each with a specific type.
So how do I use ftList.Intersect(Type) on just the TypeID?
Foreach (ftList.Intersect(TypeID = 2 | 4 | 5 )) ???
|
|
|
|
|
For arbitrary filtering, use the Where extension method - you pass in a predicate to that method which can use any of the properties of your object.
|
|
|
|
|
I found that rewriting the SQL as a stored procedure was easier to get the hierarchy that I needed
CREATE PROC sp_Hierarchy
(@ParentID int)
AS
BEGIN
WITH _items(ID, ParentID, TypeID, Depth)
AS (
SELECT ID, ParentID, TypeID, 0 AS Depth FROM tblItems WHERE ID = @ParentID
UNION ALL
SELECT t.ID, t.ParentID, t.TypeID, i.Depth + 1 FROM tblItems t JOIN _item i ON t.ParentID = i.ID
)
SELECT * FROM _item
END
Just incase somebody else needed to know
|
|
|
|
|
I want to know whether my pc is using the UPS battery power??? Intention is, i want to know if any power failure happened...
Actually i think in laptop, they are using drivers to find it.... please give your ideas...
My small attempt...
|
|
|
|
|
|
Hi all,
i'm using webservice in my form, i called this service dynamicly according to its URL, i want to save its assemply localy to read it from any application rather than load this service everytime as any c# dll.
i use this code to load webservice but its a vb.net code
Dim Client As System.Net.WebClient = New System.Net.WebClient()
Dim Stream As System.IO.Stream
Dim Provider1 As CodeDomProvider
Dim oops As CompilerError
Dim assemblyReferences As String() = New String(4) {"System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll"}
Dim ComPram As CompilerParameters
Stream = Client.OpenRead(URL)
Dim Errors As String = ""
Dim Description As New ServiceDescription
Description = ServiceDescription.Read(Stream)
Dim Importer As ServiceDescriptionImporter = New ServiceDescriptionImporter()
Importer.AddServiceDescription(Description, String.Empty, String.Empty)
Importer.ProtocolName = "Soap"
Importer.Style = ServiceDescriptionImportStyle.Client
Importer.CodeGenerationOptions = Xml.Serialization.CodeGenerationOptions.GenerateProperties
Dim nmspace As CodeNamespace = New CodeNamespace()
Dim Unit1 As CodeCompileUnit = New CodeCompileUnit()
Unit1.Namespaces.Add(nmspace)
Dim Warning As ServiceDescriptionImportWarnings
Warning = Importer.Import(nmspace, Unit1)
If (Warning = 0) Then
Provider1 = CodeDomProvider.CreateProvider("VisualBasic")
ComPram = New CompilerParameters(assemblyReferences)
Result = Provider1.CompileAssemblyFromDom(ComPram, Unit1)
Thanks for help
|
|
|
|
|
If you're calling a webservice you won't have access to its compiled DLL, it is stored on the webserver.
|
|
|
|
|
hi
i want to authenticate active directory using C#.
i have used the method given at microsoft help and support but it isnt working
errors:
1.Error 1 'ASP.logon_aspx.GetTypeHashCode()': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 822
2.Error 2 'ASP.logon_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 827
3.Error 3 'ASP.logon_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable' c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 205
they are beyond my understanding kindly help
plz its urgent!!!!!!
|
|
|
|
|
|
yeah that was exactly the link with whom i tried to implement the aforesaid task.
please note that this process at Microsoft support is giving a build time error in some file called
App_Web_zvun-gh2.1.cs
later part of that file is different every time.....
this file has lengthy coding of around 800-900 lines
the error shown is
Error 1 'ASP.logon_aspx.GetTypeHashCode()': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_zvun-gh2.1.cs 822
i am completely unaware of the error and what it is trying to point to!!! ...so please
can anybody tell me for what it is suggesting????
|
|
|
|
|
The code provided in the link is working perfectly fine.
You only have to clear the Temp Files folder and rebuilding Web Site again. Hope this will solve the problem
himanshu
|
|
|
|
|
are you talking about the temp folder in the system
C:\programfiles.......\temp
i have deleted that but the problem stills persist
additionally it is refusing me the authority to view
#do i absolutely need to configure IIS even for testing purpose?..coz it gives me error if I doesn't include integrated windows authentication as told by Microsoft
support
|
|
|
|
|
Hi all,
I want to get conversion of this format 'Mon Jun 08 15:19:42 CEST 2009' to DateTime type.
I explain the problem i'm reading from RSS feed but some of them bring that format of datetime, so my code
m_pubDate = Convert.ToDateTime(DirectCast(xNode.Element("pubDate").Value, String))
Broke for RSS Feeds that bring that format and i'm not able to convert this to DateTime.
Thank you for help
|
|
|
|
|
papy-boom wrote: m_pubDate = Convert.ToDateTime(DirectCast(xNode.Element("pubDate").Value, String))
This is not C# code.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Try DateTime.ParseExact ?
If you are getting the values in different formats, you may need to use a Regular Expression to determine which format each one uses.
This is why ISO 8601 was created.
|
|
|
|
|
Hi all,
I want to find the process ID, on one of my application. I want to do this, because later on I want to kill those process as well. I decide to use the process ID, because my application can run multiple time. Say the notepad. I can open multiple notepad docs and each have separate PIDs.
So I tried this.
Process[] servers = Process.GetProcessesByName("notepad.exe");
for (int index = 0; index < servers.Length; index++)
{
int id = servers[index].Id;
}
But each time, Process array length is zero. Even I've open multiple notepads.
Can anyone comment on this.
Thanks a lot
I appreciate your help all the time...
CodingLover
modified on Tuesday, June 23, 2009 5:46 AM
|
|
|
|
|
Amazing, I figured out that process not deal with the extension exe. If I use the process name as 'notepad' only it works fine.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
How can I close child form using Excape-Key ?
Thank you in advance
(Riaz)
|
|
|
|
|
Use Event "KeyDown". If key down is escape, then call Close();
|
|
|
|
|
Not working !
there are three text boxes and my cursor is on textbox1.
and I set Event on form level as you said.
and escap key is not working
(Riaz)
|
|
|
|
|
set : form.KeyPreview = true;
|
|
|
|