© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
35 replies
Lucho

Can someone explain to me how this works

 public bool EliminarClienteXML(BE_Cliente cliente)
        {
            acceso = new DatosXML();
            XDocument docxml = acceso.LeerXML("Clientes.xml");

            XElement elemento = docxml.Descendants("Cliente").FirstOrDefault(x => Convert.ToInt32(x.Element("DNI").Value) == cliente.dni);

            elemento.Remove();
            docxml.Save("Clientes.xml");
            return true;
        }
 public bool EliminarClienteXML(BE_Cliente cliente)
        {
            acceso = new DatosXML();
            XDocument docxml = acceso.LeerXML("Clientes.xml");

            XElement elemento = docxml.Descendants("Cliente").FirstOrDefault(x => Convert.ToInt32(x.Element("DNI").Value) == cliente.dni);

            elemento.Remove();
            docxml.Save("Clientes.xml");
            return true;
        }


I dont understand how this line works:
XElement elemento = docxml.Descendants("Cliente").FirstOrDefault(x => Convert.ToInt32(x.Element("DNI").Value) == cliente.dni);


This is how the xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Clientes>
  <Cliente>
    <Nombre>Martin</Nombre>
    <Apellido>Rodriguez</Apellido>
    <DNI>45868900</DNI>
  </Cliente>
</Clientes>
<?xml version="1.0" encoding="utf-8"?>
<Clientes>
  <Cliente>
    <Nombre>Martin</Nombre>
    <Apellido>Rodriguez</Apellido>
    <DNI>45868900</DNI>
  </Cliente>
</Clientes>
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Can someone explain how this works?
C#CC# / help
5mo ago
✅ Can someone explain how this ternary expression works
C#CC# / help
13mo ago
Can someone explain this variable and how this works?
C#CC# / help
3y ago