<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Computrónica</title>
	<link>http://www.clagir.com/computronica</link>
	<description>Computación, Electrónica, Informática</description>
	<pubDate>Sun, 29 Jun 2008 04:04:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>Métodos Virtuales</title>
		<link>http://www.clagir.com/computronica/2008/06/27/metodos-virtuales/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/metodos-virtuales/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 16:42:32 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/metodos-virtuales/</guid>
		<description><![CDATA[Una herencia sutilmente diferente pero parecida a la anterior ocurre con los méto­dos virtuales. En este caso, podemos cam­biar el funcionamiento de un método &#8220;hacia atrás&#8221;. Anteriormente vimos como una clase heredada puede implementar su propio método. En este caso, lo que pode­mos conseguir es que la clase heredada afecte al funcionamiento del método en [...]]]></description>
			<content:encoded><![CDATA[<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">Una herencia sutilmente diferente pero parecida a la anterior ocurre con los méto­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">dos virtuales. En este caso, podemos cam­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">biar el funcionamiento de un método &#8220;hacia atrás&#8221;. </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">Anteriormente vimos como </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">una clase heredada puede implementar su </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">propio método. En este caso, lo que pode­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">mos conseguir es que la clase heredada </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">afecte al funcionamiento del método en la </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">clase base. Veamos el siguiente ejemplo:</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public class Base {</font></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public void MetodoNormal () {</font></span></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 0.25pt" lang="ES-TRAD">Console.WriteLine (&#8221;Soy Base.MetodoNormal ()&#8221;);</span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 0.25pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 1.35pt" lang="ES-TRAD">}</span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">public virtual void MetodoVirtual () { </span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Soy Base.MetodoVirtual ()&#8221;);</span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 1.3pt" lang="ES-TRAD">}</span></p>
<p></span></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 1.3pt" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: 1.3pt" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public class Heredada : Base {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">new public void MetodoNormal () {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Console.WriteLine (&#8221;Soy Heredada.MetodoNormal ()&#8221;);</font></span></span></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">public override void MetodoVirtual () {</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Soy Heredada.MetodoVirtual ()&#8221;);</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">static void Main () {</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">Heredada claseHeredada = new Heredada ();</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span></font><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Base claseBase = claseHeredada;</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">claseBase.MetodoNormal ();</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">claseHeredada.MetodoNormal ();</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">claseBase.MetodoVirtual ();</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">claseHeredada.MetodoVirtual ();</span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"> </span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">}</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">}</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">Si lo ejecutamos </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD">obtenemos lo siguiente:</span></span></span></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Soy Base.MetodoNormal ()</font></span></span></span></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-family: 'Courier New'; letter-spacing: -0.2pt" lang="ES-TRAD"><font size="2">Soy Heredada.MetodoNormal ()</font></span></span></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span></span><span style="font-family: 'Courier New'; letter-spacing: -0.2pt" lang="ES-TRAD"></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Soy Heredada.MetodoVirtual ()</font></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Soy Heredada.MetodoVirtual ()</font></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Nótese como algo extraño sucede en la </span><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">tercera línea. Mientras que en el código </span><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">fuente la llamada se hace a la clase <em>Base, </em>el </span><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">resultado es el de la clase heredada, cosa </span><span style="font-family: 'Verdana','sans-serif'" lang="ES-TRAD">que no ocurre con el &#8220;método normal&#8221;.</span></font><span style="font-family: 'Verdana','sans-serif'" lang="ES-TRAD"><font size="2"> </font><font size="2"><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">La culpa de este comportamiento la tiene la combinación de las palabras clave </span><em><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">virtual </span></em><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">y <em>override, </em>que declaran y redefinen </span><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">respectivamente a los métodos virtuales. En </span><span style="font-family: 'Verdana','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">este caso el método escogido no se corres­</span><span style="font-family: 'Verdana','sans-serif'" lang="ES-TRAD">ponde con el que observa en el momen­<span style="letter-spacing: -0.3pt">to de la compilación, sino en el momento de </span><span style="letter-spacing: -0.35pt">la ejecución. Debemos fijarnos en que la </span><span style="letter-spacing: -0.2pt">definición de la instancia de la clase base se </span>hace en términos de la clase heredada al </span></font><font face="Verdana"><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.25pt" lang="ES-TRAD">comienzo del método principal. Vemos </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.15pt" lang="ES-TRAD">entonces como <em>override </em>hace un papel aná</span></span><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.2pt" lang="ES-TRAD">logo a <em>new, solo </em>que se ocupa de métodos </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.35pt" lang="ES-TRAD">virtuales, que pueden variar la funcionalidad </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.25pt" lang="ES-TRAD">incluso de las clases bases.  </span></span></font></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font face="Verdana"><span class="CharacterStyle1"><span style="font-size: 8pt; letter-spacing: -0.25pt" lang="ES-TRAD">Si la declaración de las instancias las cambia­</span></span><span class="CharacterStyle1"><span style="font-size: 8pt" lang="ES-TRAD">mos por las siguientes:</span></span></font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><font face="Verdana"><span class="CharacterStyle1"><span style="font-size: 8pt" lang="ES-TRAD"></span></span></font></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font face="Verdana"><span class="CharacterStyle1"><span style="font-size: 8pt" lang="ES-TRAD"></span></span></font><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: -0.1pt" lang="ES-TRAD">Base claseBase <em>= </em>new Base ();</span></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: -0.1pt" lang="ES-TRAD"></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD">Heredada claseHeredada <em>= </em>new </span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">Heredada ();</span></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Todo funcionará sin diferencias. Los métodos virtuales se comportarán como los </span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">demás. Lo divertido sucede cuando volve<span style="letter-spacing: -0.3pt">mos a considerar más de dos clases. ¿Qué </span><span style="letter-spacing: -0.35pt">ocurrirá en el siguiente ejemplo</span><span style="color: #15497d; letter-spacing: -0.2pt">?</span></span></font></span><span style="font-family: 'Courier New'" lang="ES-TRAD"> </span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="color: #15497d; letter-spacing: -0.2pt"></span></span></font><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">using System;</span></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">class A {</span></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">public virtual void Metodo () {</span></p>
<p></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Yo soy A.Metodo ()&#8221;);</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">class B : A {</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">public override void Metodo () {</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Yo soy B.Metodo ()&#8221;);</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">class C : B {</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">new public virtual void Metodo () {</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Yo soy C.Metodo ()&#8221;);</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">class D : C {</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">public override void Metodo () {</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">Console.WriteLine (&#8221;Yo soy D.Metodo ()&#8221;);</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">static void Main () {</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">D d = new D ();</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">A a = d;</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">B b = d;</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">C c = d;</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">a.Metodo ();</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">b.Metodo ();</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">c.Metodo ();</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">d.Metodo ();</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Courier New'" lang="ES-TRAD">}</span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">Hemos usado todas las combinaciones </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">posibles. Primero declaramos un método vir­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">tual, luego lo redefinimos con <em>override.</em></span></font></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">En C </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">se usa <em>new </em>y se vuelve a emplear virtual, y en </span></font><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">D se cierra el ciclo y se utiliza de nuevo <em>overri­de. </em>A continuación creamos una instancia de </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.5pt" lang="ES-TRAD">la clase más baja en el nivel de herencia, y el </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: 0.65pt" lang="ES-TRAD">resto de las instancias las hacemos </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">depender de ella. Como siempre, termina­mos llamando a todos los métodos. ¿Qué </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">ocurrirá? Si hemos seguido el razonamiento hasta aquí, encontraremos rápidamente la </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">respuesta: las clases que contengan méto­</span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">dos virtuales perderán su funcionalidad y las </span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.05pt" lang="ES-TRAD">demás no. El problema está en <em>a.Metodo() </em></span></span><span class="CharacterStyle1"><span style="font-size: 8pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">ya que tenemos dos opciones, o bien se queda con el método de B o bien salta hasta </span></span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.45pt" lang="ES-TRAD"><font size="2">D que es la instancia activa. </font></span><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.45pt" lang="ES-TRAD">El resultado final </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">es el siguiente, esto es, la clase que se ocupa </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">de la implementación es la más cercana en el </span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">árbol de herencias:</span></font></span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="font-size: 8pt; font-family: 'Verdana','sans-serif'" lang="ES-TRAD"></span></font><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2">Yo soy B.Metodo ( )</font></span></span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"></span><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2">Yo soy B.Metodo ( )</font></span></span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"></span></span><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"></span><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2">Yo soy D.Metodo ( )</font></span></span></p>
<p><span style="font-size: 9pt; color: black; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD"></span></span><span style="font-size: 11pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.15pt" lang="ES-TRAD">Yo soy D.Metodo ( )</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/metodos-virtuales/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ocultación de Métodos en C#</title>
		<link>http://www.clagir.com/computronica/2008/06/27/ocultacion-de-metodos-en-c/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/ocultacion-de-metodos-en-c/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 16:17:16 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/ocultacion-de-metodos-en-c/</guid>
		<description><![CDATA[Una vez estudiado el modo en el que los métodos se intercambian información a través de parámetros, volvemos al repaso de posibles modificadores que puede preceder a la declaración de un método. Ya hemos hablado de la herencia, esto es, de cómo una clase es capaz de obtener los miembros de una clase base. Sin [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.1pt" lang="ES-TRAD">Una vez estudiado el modo en el que los métodos se intercambian información a </span><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD">través de parámetros, volvemos al repaso de posibles modificadores que puede pre<span class="CharacterStyle2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.1pt">ceder a la declaración de un método. Ya </span></span><span class="CharacterStyle2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.05pt">hemos hablado de la herencia, esto es, de </span></span><span class="CharacterStyle2"><span style="font-family: 'Arial','sans-serif'">cómo una clase es capaz de obtener los <span style="letter-spacing: -0.05pt">miembros de una clase base. Sin embargo no sabemos cómo reimplementar en una </span><span style="letter-spacing: -0.15pt">clase heredada la funcionalidad de un </span>miembro de la base. Para esto precisa­<span style="letter-spacing: -0.1pt">mente tenemos la instrucción <em>new, </em><span>teniendo lo siguiente:</span></span></span></span></span></p>
<p><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-family: 'Arial','sans-serif'"><span style="letter-spacing: -0.1pt"><span></span></span><span style="color: #14599a"></span></span></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public class Base {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public static void MetodoBase () {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Console.WriteLine (&#8221;Yo soy Base.MetodoBase ()&#8221;);</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">public class Heredada : Base { </span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">public static void Main () { </span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">MetodoBase ();</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span></span><span></span><span></span><span></span><span></p>
<p style="margin: 10.8pt 0cm 0pt" class="Style1"><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">new</span><strong> </strong><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">public static void MetodoBase () {</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: 0.15pt" lang="ES-TRAD">Console.WriteLine (&#8221;Yo soy Heredada.MetodoBase ()&#8221;);</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span></p>
<p></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-family: 'Courier New'"></span></span></span><span><font size="2">Tenemos dos clases, donde una hereda <span style="letter-spacing: -0.15pt">de la otra. La segunda además redefine el </span><span style="letter-spacing: 0.35pt">método <em>MetodoBase() </em>gracias al modifica­</span><span style="letter-spacing: -0.2pt">dor <em>new. </em></span></font><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">Al ejecutar el programa, </span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">se vería lo siguiente:</span></font></span></p>
<p><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font></span></em><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Yo soy Heredada .MetodoBase ( )</font></span></span></span></em></p>
<p><span><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">lo que verifica que la redefinición ha sido un </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">éxito. Si eliminamos el parámetro new el pro­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.05pt" lang="ES-TRAD">grama seguiría compilando, pero obtendría­</span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">mos una advertencia:</span></font></span></p>
<p><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font></span></em><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -1.1pt" lang="ES-TRAD"><font size="2">New. cs ( 18 ) warning CS0108 :</font></span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">The keyword new is required on</font></span></span><font size="2"><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -1pt" lang="ES-TRAD">&#8216; Heredada . MetodoBas e &#8216; because it </span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD">hides inherited member</span></span></font><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">&#8216; Base .MetodoBase &#8216;</font></span></span></span></em><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"> </span></em><em><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: -1pt" lang="ES-TRAD">Compilation succeeded - 1 warning(s) s )</span><span style="font-family: 'Bookman Old Style','serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><font size="2"> </font></span></p>
<p></span></em><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">El compilador nos ayuda a no ocultar </span><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">métodos sin querer. Igualmente, si la clase </span><em><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Base </span></em><span style="font-size: 10pt; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">no tuviera ninguna definición para </span><em><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD">MetodoBase(), </span></em><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD">el compilador también nos <span class="CharacterStyle1"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt">advertiría de que no estamos redefiniendo </span></span><span class="CharacterStyle1"><span style="font-family: 'Arial','sans-serif'">nada.</span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span></span><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">Todo esto se puede complicar un poco </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">más. Supongamos que tenemos una clase </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">B que hereda de A, y una clase C que here­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">da de B. Pues bien, es posible redefinir un </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">método de A en B, sin que C note el cambio, teniendo lo siguiente:</span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font size="2"> </font></span></p>
<p><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></span></p>
<p><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public class A {</font></span></span></span></p>
<p><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public static void MetodoBase () {</font></span></span></span></p>
<p><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: 0.2pt" lang="ES-TRAD">Console.WriteLine (</span><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: 0.2pt" lang="ES-TRAD">&#8220;Yo soy A.MetodoBase ()&#8221;); </span></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-size: 8pt; font-family: 'Courier New'; letter-spacing: 0.2pt" lang="ES-TRAD"></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">public class B : A {</font></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">new prívate static void MetodoBase () {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Console.WriteLine (&#8221;Yo soy B.MetodoBase ()&#8221;);</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">public class C : B { </span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">static void Main () { </span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">MetodoBase ();</span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">El método C imprimiría por pantalla &#8220;Yo </span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">soy A.MetodoBase ()&#8221; gracias a que en B </span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">hemos marcado la redefinición como priva­</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">da, lo que la restringe a dicha clase. Si cam­biamos <em>prívate </em>por <em>public, </em>o hacemos la lla­</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">mada dentro de B conseguiremos &#8220;Yo soy </span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">B.MetodoBase ()&#8221;. Tenemos una doble herencia anidada de clases en la que la ocul­</span><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">tación de métodos es solamente parcial.</span></span></p>
<p align="right"><span style="color: #394a68; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">Continúa en <a href="http://www.clagir.com/computronica/2008/06/27/metodos-virtuales/">Métodos Virtuales</a></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/ocultacion-de-metodos-en-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parámetros en C# - Parámetros Múltiples</title>
		<link>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-multiples/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-multiples/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:51:07 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-multiples/</guid>
		<description><![CDATA[No siempre sabemos con certeza el núme­ro de parámetros que vamos a enviar a un método. En ese caso podemos emplear la palabra clave params para denotar que el número de parámetros será en realidad un array de parámetros de tamaño inicialmente desconocido, teniendo:
using System;
class Parametros {
static void Main () {
int[] parametros = {l, 2, [...]]]></description>
			<content:encoded><![CDATA[<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">No siempre sabemos con certeza el núme­<span style="letter-spacing: -0.2pt">ro de parámetros que vamos a enviar a un </span><span style="letter-spacing: -0.05pt">método. En ese caso podemos emplear la </span><span style="letter-spacing: -0.2pt">palabra clave <em>params </em>para denotar que el número de parámetros será en realidad un array de parámetros de tamaño inicialmente </span><span style="letter-spacing: -0.1pt">desconocido, teniendo:</span></span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="letter-spacing: -0.1pt"></span></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">class Parametros {</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">static void Main () {</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">int[] parametros = {l, 2, 3, 4, 5}; </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">CuentaArgumentos (parametros); </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD">CuentaArgumentos (1, 2, 3);</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">CuentaArgumentos ();</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">} </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">static void CuentaArgumentos <strong>(params </strong>int[] parametros) { </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">Console.Write (&#8221;He recibido {O} argumentos:&#8221;, parametros.Length); </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD">for (int i = O; i &lt; parametros.Length; i++)</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Console.Write (&#8221; {0}&#8221;, parametros[i]);</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Console.WriteLine ();</font></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"> </span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">}</span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">}</span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">En el programa hemos definido un </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.05pt" lang="ES-TRAD">método llamado <em>CuentaArgumentos </em>al que </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">le hemos añadido <em>params </em>en su definición. Esto nos permite invocarlo de tres maneras </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">distintas en el método principal. Da igual si lo </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">llamamos con un array como argumento, </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">una lista de números o sencillamente nada. </span></span></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.05pt" lang="ES-TRAD">El método será capaz de controlar adecua­</span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">damente cada situación:</span></span></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">He recibido 5 argumentos: 1 2 3 4 5 </span></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"></span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.3pt" lang="ES-TRAD">He recibido 3 argumentos: 1 2 3 </span></p>
<p></span></span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.3pt" lang="ES-TRAD"></span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'" lang="ES-TRAD">He recibido O argumentos:</span></p>
<p><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">Cabe preguntarse qué pasaría si eliminá­</span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">ramos <em>params </em>de la definición, puesto que formalmente seguiría siendo correcta. El </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">resultado es el esperado, tal como se muestra a continuación:</span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 116%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2">Params.cs (8) error CS1501: No overload for method &#8216;CuentaArgumentos&#8217; takes &#8216;3&#8242; arguments </font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="letter-spacing: 0.4pt">Params.cs(8) error CS8006: Could not find any applicable functíon for this argument list </span></font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="letter-spacing: 0.4pt"></span>Params.cs(9) error CS1501: No overload for method &#8216;CuentaArgumentos&#8217; takes &#8216;O&#8217; arguments </font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="letter-spacing: 0.4pt">Params.cs(9) error CS8006: Could not find any applicable function for this argument list </span></font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"><font size="2"><span style="letter-spacing: 0.4pt"></span>Compilation failed: 4 error(s), 0 warnings</font></span></p>
<p><span style="font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Esto significa que puede que la definición </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.1pt" lang="ES-TRAD">del método sea válida, pero sus invocacio­</span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">nes no lo son.</span></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-multiples/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parámetros en C# - Parámetros Exteriores</title>
		<link>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-exteriores/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-exteriores/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:42:55 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-exteriores/</guid>
		<description><![CDATA[Un tercer tipo de parámetros parecido al anterior, es aquél que viene precedido por la palabra clave out. En este caso, permitimos que sea el método de destino el que realice la primera asignación a la variable.
Supongamos que necesitamos una función que divida en dos una palabra y devuelva los dos trozos resultantes. Pues bien, [...]]]></description>
			<content:encoded><![CDATA[<p style="margin: 1.8pt 0cm 0pt; line-height: 112%; text-align: justify" class="Style2"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">Un tercer tipo de parámetros parecido al anterior, es aquél que viene precedido por la </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">palabra clave <em>out. </em>En este caso, permitimos </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">que sea el método de destino el que realice </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">la primera asignación a la variable.</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">Supongamos que necesitamos una función </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">que divida en dos una palabra y devuelva los </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">dos trozos resultantes. Pues bien, entonces </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">haríamos lo que muestra en el siguiente código:</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">class Parametros {</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">static void Main () {</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">string izquierda, derecha;</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">string cadena = &#8220;Me van a cortar por la mitad&#8221;; </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">Console.WriteLine (&#8221;Cadena original = &#8216;{0}&#8217;&#8221;, cadena); </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD">Divide (cadena, out izquierda, out derecha);</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">Console.WriteLine (&#8221;Primera parte = &#8216;{0}&#8217;&#8221;, izquierda); </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">Console.WriteLine (&#8221;Segunda parte = &#8216;{0}&#8217;&#8221;, derecha);</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.8pt" lang="ES-TRAD">static void Divide (string cadena, <strong>out </strong>string izquierda, <strong>out </strong>string derecha) { </span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD">izquierda = cadena.Substring (O, cadena.Length / 2);</span><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">derecha = cadena.Substring (cadena.Length / 2);</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span></p>
<p><span class="CharacterStyle2"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><font face="Courier New">}</font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">A</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">l ejecutarlo, daría el siguiente resultado por </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">pantalla:</span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD"><font size="2"> </font></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><font size="2"><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">Cadena original = &#8216;Me van a cortar </span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD">por la mitad&#8217;</span></span></font></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><font size="2"><span class="CharacterStyle2"><span style="font-family: 'Courier New'" lang="ES-TRAD"></span></span></font><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"><font size="2">Primera parte = &#8216;Me van a corta&#8217;</font></span></span></p>
<p></span></span><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"><font size="2">Segunda parte = &#8216;r por la mitad&#8217;</font></span></span></p>
<p><span class="CharacterStyle2"><span style="font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">El programa hace uso del método </span></span><span class="CharacterStyle2"><em><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">Substring, </span></em></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">miembro de <em>System.String </em>que <span style="letter-spacing: -0.15pt">nos permite extraer fácilmente subconjun­</span><span style="letter-spacing: 0.5pt">tos de cadenas de texto. Como vemos, </span><span style="letter-spacing: -0.15pt">pese a que las cadenas izquierda y derecha </span><span style="letter-spacing: -0.25pt">no estaban inicializadas, el compilador no ha puesto ningún problema a que fuera el </span><span style="letter-spacing: -0.15pt">método <em>Divide O </em>el que realizará dicha asig­</span>nación.</span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">Si en lugar de <em>out, </em>hubiéramos emplea­</span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">do <em>ref, </em>habríamos obtenido el siguiente error </span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">de compilación:</span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span></span></p>
<p><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span class="CharacterStyle2"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">Divide.cs(10) error CS0165: Use of </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.65pt" lang="ES-TRAD">unassigned local variable &#8216;izquierda&#8217; Divide .cs (13) error CS0165: Use of </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">unassigned local variable &#8216;derecha&#8217; </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.85pt" lang="ES-TRAD">Compilation f ailed: 2 error (s ) , </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'" lang="ES-TRAD">O warnings</span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-exteriores/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parámetros en C# - Por valor</title>
		<link>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-valor/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-valor/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:35:27 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-valor/</guid>
		<description><![CDATA[El modo más sencillo de pasar el valor de una variable a un método se puede ver en el siguiente ejemplo: 
using System;class Parametros {
static void Main () {

int a = 2; 
int b = 3;
int c = Suma (a, b);
Console.WriteLine (&#8221;{0} + {1} = {2}&#8221;, a, b, c);

}
static int Suma (int a, int b) { [...]]]></description>
			<content:encoded><![CDATA[<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">El modo más sencillo de pasar el valor de </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">una variable a un método se puede ver en el siguiente ejemplo:</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; color: #19353c; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><font size="2" face="Verdana"> </font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: 1pt" lang="ES-TRAD">using System;</span></span></span><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: 1pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">class Parametros {</span></span></span></p>
<blockquote><p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">static void Main () {</font></span></span></p></blockquote>
<blockquote>
<blockquote><p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">int a </span><span style="font-size: 8pt; color: #2c2825; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">= </span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD">2; </span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: -0.45pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; font-family: 'Courier New'; letter-spacing: -0.2pt" lang="ES-TRAD">int b = </span><span style="font-size: 8pt; color: black; font-family: 'Verdana','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">3;</span></p>
<p><span style="font-size: 8pt; color: black; font-family: 'Verdana','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">int c = Suma (a, b);</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"><font size="2">Console.WriteLine (&#8221;{0} + {1} = {2}&#8221;, a, b, c);</font></span></span></p></blockquote>
</blockquote>
<blockquote><p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">}</span></span></p></blockquote>
<blockquote><p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">static int Suma (int a, int b) { </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 120%; font-family: 'Courier New'" lang="ES-TRAD">return a + b;</span><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><font size="2" face="Verdana"> </font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><font size="2" face="Verdana">}</font></span></span></p></blockquote>
<p><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"><font size="2" face="Verdana">}</font></span></span><span class="CharacterStyle1"><span style="color: #19353c" lang="ES-TRAD"></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">Se escriben el nombre de </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">las variables a la hora de invocar el método, y </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: 0.1pt" lang="ES-TRAD">cuando se define, la precedemos por su </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">tipo. </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">Así, al ejecutar el códi­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">go obtenemos:</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"> </span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 112%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'" lang="ES-TRAD">2 + </span><span style="font-size: 8pt; line-height: 115%" lang="ES-TRAD"><font face="Verdana">3 = 5</font></span></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-valor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parámetros en C#</title>
		<link>http://www.clagir.com/computronica/2008/06/27/parametros-en-c/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/parametros-en-c/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:35:01 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/parametros-en-c/</guid>
		<description><![CDATA[Los parámetros en C# son el modo típico que tie­nen los métodos de intercambiar algún tipo de información con otros métodos o ele­mentos del programa. Veamos las diversas maneras que tenemos de de transferir estos parámetros de un lado a otro.
Por valor
Por referencia
Parámetros exteriores
Parámetros múltiples
]]></description>
			<content:encoded><![CDATA[<p><span class="CharacterStyle1"><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font color="#000000"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Los parámetros en C# son el modo típico que tie­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.35pt" lang="ES-TRAD">nen los métodos de intercambiar algún tipo </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">de información con otros métodos o ele­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">mentos del programa. Veamos las diversas maneras que tenemos de de transferir estos </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">parámetros de un lado a otro.</span></span></font></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font color="#000000"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span></font></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><a href="http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-valor/">Por valor</a></span></strong></span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></strong></span></span></span><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><a href="http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-referencia/">Por referencia</a></span></strong></span></span></strong></span></p>
<p><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></strong></span></span></strong></span><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><a href="http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-exteriores/"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; font-family: 'Arial','sans-serif'" lang="ES-TRAD">Parámetros </span></strong></span><span class="CharacterStyle1"><strong><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font color="#000000">exteriores</font></span></strong></span></a></span></strong></span></span></strong></span></p>
<p><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></strong></span></span></strong></span></span></strong></span><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 125%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; color: #2c2825; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span class="CharacterStyle1"><strong><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><font color="#000000"><span class="CharacterStyle2"><strong><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><a href="http://www.clagir.com/computronica/2008/06/27/parametros-en-c-parametros-multiples/">Parámetros múltiples</a></span></strong></span></font></span></strong></span></span></strong></span></span></strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/parametros-en-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parámetros en C# - Por referencia</title>
		<link>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-referencia/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-referencia/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:34:23 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Programación]]></category>

		<category><![CDATA[Computación]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-referencia/</guid>
		<description><![CDATA[Supongamos ahora que queremos definir un método que intercambie el valor de sus dos argumentos. De acuerdo con el ejemplo anterior, sería hacer lo siguiente:
using System;
class Parametros {
static void Main () {
int a = 2;
int b = 3;
Console.WriteLine (&#8221;a = {O}, b = {1}&#8221;, a, b); 
Intercambia (a, b);
Console.WriteLine (&#8221;a = {O}, b = {1}&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">Supongamos ahora que queremos definir <span style="letter-spacing: -0.35pt">un método que intercambie el valor de sus </span><span style="letter-spacing: -0.25pt">dos argumentos. De acuerdo con </span><span style="letter-spacing: -0.35pt">el ejemplo anterior, sería hacer lo siguiente:</span></span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 122%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"><span style="letter-spacing: -0.35pt"></span><strong><span style="color: #2c2825"></span></strong></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">using System;</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">class Parametros {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">static void Main () {</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">int a = 2;</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">int b = </span></span><span class="CharacterStyle1"><span style="color: black" lang="ES-TRAD"><font face="Verdana">3;</font></span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black" lang="ES-TRAD"></span></span></font><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">Console.WriteLine (&#8221;a = {O}, b = {1}&#8221;, a, b); </span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD">Intercambia (a, b);</span></span></font></p>
<p><font size="2"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span></font><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">Console.WriteLine (&#8221;a = </span><span style="font-size: 8pt; color: #2c2825; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">{O},</span><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"> b </span><span style="font-size: 8pt; color: #2c2825; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">= </span><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">{1}&#8221;,</span><span style="font-size: 8pt; color: #2c2825; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"> </span><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">a, b);</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 128%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 118%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">static void Intercambia (int a, int b) { </span></p>
<p><span style="font-size: 8pt; color: black; line-height: 118%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><span style="font-size: 8pt; color: black; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD">int temp = a;</span></p>
<p><span style="font-size: 8pt; color: black; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">a = b;</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">b = temp;</font></span></span></p>
<p><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"></span></span><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"> </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="color: black; font-family: 'Courier New'" lang="ES-TRAD"><font size="2">}</font></span></span></span></span></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD"><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">Sin embargo, nos veremos contrariados al comprobar que el programa no ejecuta </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">ninguna acción:</span></span></p>
<p></span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 111%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; line-height: 117%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">a = 2, b = </span><span style="font-size: 7pt; line-height: 117%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.4pt" lang="ES-TRAD">3 </span></p>
<p><span style="font-size: 7pt; line-height: 117%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.4pt" lang="ES-TRAD"></span><span style="font-size: 8pt; line-height: 117%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">a = 2, b <span style="color: #2c2825">= </span></span><span style="font-size: 7pt; line-height: 117%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.35pt" lang="ES-TRAD">3</span></p>
<p><span style="font-size: 7pt; line-height: 117%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.35pt" lang="ES-TRAD"></span><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">Lo que ha pasado es que las operacio­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">nes que hemos realizado con las variables </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.1pt" lang="ES-TRAD">dentro del método <em>Intercambia o </em>no han </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">tenido efecto. Pese a que nosotros hemos </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">asignado nuevos valores que intercambia</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">ban los antiguos, todo ha seguido como al </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">principio. Lo que ocurre es que el método no </span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.4pt" lang="ES-TRAD">altera el valor de las variables originales, ya </span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">que trabaja sobre una <em>copia </em>de éstas.</span></font><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2"> </font></span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD">Precisamente esto es lo que se solucio­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">na con la llamada por referencia de paráme­</span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">tros. Si cambiamos la defini­</span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">ción del método por:</span></font></span><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.15pt" lang="ES-TRAD"><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></font><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">static void Intercambia </span><strong><span style="font-size: 7pt; line-height: 118%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">(ref </span></strong><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'; letter-spacing: -0.35pt" lang="ES-TRAD">int a, </span><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD">ref int b) {</span></p>
<p></span><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD">&#8230;</span></p>
<p><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD">}</span></p>
<p><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD"></span><font size="2"><span style="font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">y si, por consiguiente, lo invocamos inclu­</span><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD">yendo las palabras clave <em>ref.</em></span></font></p>
<p><font size="2"><span style="font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span><span style="font-size: 8pt; line-height: 118%; font-family: 'Courier New'" lang="ES-TRAD"></span></font><span style="font-size: 8pt; line-height: 135%; font-family: 'Courier New'" lang="ES-TRAD">Intercambia (ref a, </span><strong><span style="font-size: 7pt; line-height: 135%; font-family: 'Courier New'" lang="ES-TRAD">ref </span></strong><span style="font-size: 8pt; line-height: 135%; font-family: 'Courier New'" lang="ES-TRAD">b);</span></p>
<p><span style="font-size: 8pt; line-height: 135%; font-family: 'Courier New'" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 113%; font-family: 'Arial','sans-serif'" lang="ES-TRAD">el resultado ahora sí es el deseado:</span></span></p>
<p><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 113%; font-family: 'Arial','sans-serif'" lang="ES-TRAD"></span></span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.4pt" lang="ES-TRAD">a = 2, b = </span><span style="font-size: 7pt; line-height: 115%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.4pt" lang="ES-TRAD">3</span></p>
<p><span style="font-size: 7pt; line-height: 115%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.4pt" lang="ES-TRAD"> </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.1pt" lang="ES-TRAD">a = </span><span style="font-size: 7pt; line-height: 115%; font-family: 'Bookman Old Style','serif'; letter-spacing: -0.1pt" lang="ES-TRAD">3, </span><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.1pt" lang="ES-TRAD">b = 2</span></p>
<p><span style="font-size: 8pt; line-height: 115%; font-family: 'Courier New'; letter-spacing: -0.1pt" lang="ES-TRAD"></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.2pt" lang="ES-TRAD">Al introducir <em>ref </em>como prefijo de invoca­</span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.25pt" lang="ES-TRAD">ción dé los parámetros, evitamos el efecto </span></span><span class="CharacterStyle1"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'; letter-spacing: -0.3pt" lang="ES-TRAD">que comentábamos al principio. Por lo tanto, lo que hagamos sobre las variables en el método, afecta a las variables originales.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/parametros-en-c-por-referencia/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Clasificación de las Redes Neuronales</title>
		<link>http://www.clagir.com/computronica/2008/06/27/clasificacion-de-las-redes-neuronales/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/clasificacion-de-las-redes-neuronales/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 14:39:26 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Informática]]></category>

		<category><![CDATA[Inteligencia Artificial]]></category>

		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/clasificacion-de-las-redes-neuronales/</guid>
		<description><![CDATA[Las Redes Neuronales según su realidad biológica
Modelos de tipo biológico.
Modelo dirigido a aplicación.

Las Redes Neuronales según su topología
Perceptrón
Hopfield
Kohonen
]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><strong>Las Redes Neuronales según su realidad biológica</strong></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/2008/06/27/las-redes-neuronales-segun-su-realidad-biologica/">Modelos de tipo biológico.</a></span></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/2008/06/27/las-redes-neuronales-segun-su-realidad-biologica/">Modelo dirigido a aplicación.</a></span></span></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><strong><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"></span></strong></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><strong><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE">Las Redes Neuronales según su topología</span></strong></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/2008/06/27/perceptron/">Perceptrón</a></span></span></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/2008/06/27/hopfield/">Hopfield</a></span></span></span></span></span></p>
<p><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/2008/06/27/kohonen/">Kohonen</a></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'Calibri','sans-serif'" lang="ES-VE"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'" lang="ES-VE"></span></span></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/clasificacion-de-las-redes-neuronales/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Kohonen</title>
		<link>http://www.clagir.com/computronica/2008/06/27/kohonen/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/kohonen/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 14:35:56 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Informática]]></category>

		<category><![CDATA[Inteligencia Artificial]]></category>

		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/kohonen/</guid>
		<description><![CDATA[Este es un esquema de red neuronal, el cual tiene la capacidad de crear mapas de características, se cree que estos se forman por genética o por aprendizaje. Tiene como objetivo la de demostrar que un estímulo externo es suficiente para formar dichos mapas. Maneja el aprendizaje no supervisado, presenta una arquitectura de capas y [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; color: black; font-family: 'Arial','sans-serif'">Este es un esquema de red neuronal, el cual tiene la capacidad de crear mapas de características, se cree que estos se forman por genética o por aprendizaje. Tiene como objetivo la de demostrar que un estímulo externo es suficiente para formar dichos mapas. Maneja el aprendizaje no supervisado, presenta una arquitectura de capas y la dirección de la información es unidireccional. Con este tipo de redes se quiere clasificar los patrones de entrada en grupos de características similares, para así activar una única salida constantemente.</span></p>
<p><span style="font-size: 10pt; color: black; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; font-family: 'Arial','sans-serif'">El aprendizaje, según <a href="http://www.electronica.com.mx/neural/">Redes Neuronales Artificiales</a>, se lleva a cabo de la siguiente manera:</span><span style="font-size: 10pt; font-family: 'Arial','sans-serif'" lang="ES-VE"></span><span style="font-size: 10pt; color: black; font-family: 'Arial','sans-serif'">“Supongamos que tenemos patrones de entrada n-dimensionales.</span></p>
<ol>
<li><span style="font-size: 10pt; color: black; font-family: 'Arial','sans-serif'">Aleatorizar los pesos de las conexiones. Normalizar los pesos de las conexiones incidentes de cada   unidad de salida sobre la unidad: dividir cada conexión por la raíz cuadrada de la suma de los cuadrados de las conexiones de cada unidad. Normalizar igualmente los datos de entrada.</span></li>
<li style="margin: 0cm 0cm 10pt; color: black; line-height: normal; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'">Aplicar un patrón de entrada. </span></li>
<li style="margin: 0cm 0cm 10pt; color: black; line-height: normal; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; font-family: 'Arial','sans-serif'">Calcular alguna medida de similitud/disimilitud (producto interno, distancia euclídea o de Mahalanobis, etc.) entre las entradas y los pesos de las conexiones. </span></li>
<li style="margin: 0cm 0cm 10pt; color: black; line-height: normal; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'">La unidad de salida con los pesos más parecidos al patrón de entrada es declarada ganadora. El vector de pesos de la unidad ganadora, se convierte en el centro de un grupo de vectores cercanos a él. </span></li>
<li style="margin: 0cm 0cm 10pt; color: black; line-height: normal; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'">Modificar los pesos de los vectores de pesos Wj &#8220;cercanos&#8221; a Wc (distancia menor a D). De esta manera conseguimos que los vectores de pesos de la unidad ganadora y de su &#8220;vecindario&#8221; se parezcan cada vez más al patrón de entrada que hace ganar a esa unidad. </span></li>
<li style="margin: 0cm 0cm 10pt; color: black; line-height: normal; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Arial','sans-serif'">Repetir los pasos 1 a 4 con todos los patrones de entrada”. </span></li>
</ol>
<p><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">Luego de que se lleva a cabo este aprendizaje, se puede usar esta red para clasificar los patrones de entradas en espacios n-dimensional. Una clase de patrones controlará una neurona específica, la cual representará el centro de la esfera n-dimensional, esta será la mas activa frente a los patrones mas parecidos a su vector de pesos.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/kohonen/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hopfield</title>
		<link>http://www.clagir.com/computronica/2008/06/27/hopfield/</link>
		<comments>http://www.clagir.com/computronica/2008/06/27/hopfield/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 14:35:39 +0000</pubDate>
		<dc:creator>computronica</dc:creator>
		
		<category><![CDATA[Informática]]></category>

		<category><![CDATA[Inteligencia Artificial]]></category>

		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.clagir.com/computronica/2008/06/27/hopfield/</guid>
		<description><![CDATA[Estas se usan para situaciones probabilísticas, recurrentes que entrarían dentro de las memorias autoasociativas, aprendiendo a reconstruir los patrones de entrada que han memorizado durante el aprendizaje. Se trabajan con una capa de interconexión total, de adaptación probabilística y regla de aprendizaje no supervisado.
Estas dan soluciones dinámicas, las cuales en ocasiones no son muy recomendables, [...]]]></description>
			<content:encoded><![CDATA[<p style="margin: 0cm 0cm 10pt; text-align: justify" class="MsoNormal"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">Estas se usan para situaciones probabilísticas, recurrentes que entrarían dentro de las memorias autoasociativas, aprendiendo a reconstruir los patrones de entrada que han memorizado durante el aprendizaje. Se trabajan con una capa de interconexión total, de adaptación probabilística y regla de aprendizaje no supervisado.</span></p>
<p style="margin: 0cm 0cm 10pt; text-align: justify" class="MsoNormal"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">Estas dan soluciones dinámicas, las cuales en ocasiones no son muy recomendables, sin embargo, Hopfield busca la manera de entregar con una memoria de este tipo que sea capaz de entregar soluciones estables. Permite que el estado de cada neurona sea actualizado un número indefinido de veces, sin importar el resto de las neuronas de la red.</span></p>
<p style="margin: 0cm 0cm 10pt; text-align: justify" class="MsoNormal"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">Consiste en un conjunto de N elementos de proceso interconectadas, los operadores de entrada son también salida y los valores de activación son binarios, los cuales determinarán el estado del sistema. Se dice que cuando este valor de activación es constante es estable.</span></p>
<p><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">El aprendizaje de las redes de Hopfield se hace en base a la regla de Cooper-Hebb, que depende la conexión de los patrones que se desean aprender. Según <a href="http://www.electronica.com.mx/neural/">Redes Neuronales Artificiales</a>, el entrenamiento se realiza de la siguiente manera: </span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></p>
<ol type="1">
<li style="margin: 0cm 0cm 10pt; color: black; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'">“Elegir un número de neuronas que cumpla el criterio del 15%. </span></li>
<li style="margin: 0cm 0cm 10pt; color: black; text-align: justify; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-size: 10pt; line-height: 115%; font-family: 'Arial','sans-serif'">Codificar los ítems que queremos memorizar de forma que los patrones para representarlos se parezcan lo menos posible entre sí, para aproximarnos a la condición de pseudo-ortogonalidad. </span></li>
</ol>
<p style="margin: 0cm 0cm 10pt; text-align: justify" class="MsoNormal"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">Calcular los pesos de las conexiones según la regla de Cooper-Hebb”.</span></p>
<p></span></p>
<p style="margin: 0cm 0cm 10pt; text-align: justify" class="MsoNormal"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'">En la siguiente figura, tomada de <a href="http://www.electronica.com.mx/neural/">Redes Neuronales Artificiales</a>, se presenta el “modelo de Red de Hopfield de 3 unidades”:</span></p>
<p><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></a></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></a></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></a></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></a></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></a></span></span><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"></p>
<p style="text-align: center"><img width="347" src="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" alt="hopfield.JPG" height="312" style="width: 347px; height: 312px" /></p>
<p style="text-align: center">&nbsp;</p>
<p align="left" style="text-align: center"><a href="http://www.clagir.com/computronica/wp-content/uploads/2008/06/hopfield.JPG" title="hopfield.JPG"><span style="font-size: 10pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"></span></a></p>
<p></a></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clagir.com/computronica/2008/06/27/hopfield/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
