Życzę wszystkim aby spędzili Święta w taki sposób w jaki sobie wymarzą i z tymi ludźmi, przy których będą czuli się najlepiej.
Serdecznie pozdrawiam
Michał Komorowski
Serdecznie pozdrawiam
Michał Komorowski
The blog about programming, working in IT and not only
delegate void Fun(); ... Listarray = new List (); for (int i = 0; i < 5; ++i) { array.Add(delegate() { Console.WriteLine(i); }); } for (int i = 0; i < 5; ++i) { array[i](); }
[CompilerGenerated]
private sealed class DisplayClass
{
public int i;
public void b_0()
{
Console.WriteLine(this.i);
}
}
DisplayClass d = new DisplayClass(); Listarray = new List (); for (d.i = 0; d.i < 5; ++d.i) { array.Add(d.b_0); } for (int i = 0; i < 5; ++i) { array[i](); }
for (int i = 0; i < 5; ++i)
{
int j = i;
array.Add(delegate() { Console.WriteLine(j); });
}
...
ListBox lb = new ListBox();
lb.AutoPostBack = true;
lb.SelectedIndexChanged += new EventHandler(lb_SelectedIndexChanged);
lb.Items.Add("a");
lb.Items.Add("b");
lb.Items.Add("c");
this.Panel.Controls.Add(lb);
...
...
this.DataList.DataSource = new string[] { "a", "b", "c" };
this.DataList.DataBind();
...
...
<asp:DataList ID="DataList" runat="server" EnableViewState="false">
<ItemTemplate>
<asp:Button ID="Button" runat="server" Text="<%# Container.DataItem %>" OnClick="OnClick" />
</ItemTemplate>
</asp:DataList>
...
...
<head runat="server">
<link id="link"
type="text/css"
rel="Stylesheet"
href="~/style.css"
runat="server" />
</head>
...
this.link.Visible = false;to nie zostanie wzięta pod uwagę podczas renderowania strony i styl nie zostanie zastosowany do strony. Odwrotnie, jeśli kontrolka będzie widoczna:
this.link.Visible = true;to podczas renderowania strony zostanie uwzględniona i styl zostanie zastosowany do strony. Bardzo proste ale skuteczne.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='Transformation.xsl'?>
<A>
<B>
bbb
</B>
<B>
bbb
</B>
</A>
Transformajca wygląda natomiast tak:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" standalone="no" omit-xml-declaration="yes" encoding="windows-1250" />
<xsl:template match="B" >
<LI>
<xsl:value-of select="current()"/>
</LI>
</xsl:template>
<xsl:template match="A" >
<HTML>
<HEAD>
</HEAD>
<BODY>
<UL>
<xsl:apply-templates select="B"/>
</UL>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
... <A xmlns="a.b.c"> ...
... <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="a.b.c"> ...
...
<xsl:template match="test:B" >
<LI>
<xsl:value-of select="current()"/>
</LI>
</xsl:template>
...
protected void Page_Load(object sender, EventArgs e)
{
...
Control control = LoadControl("~/MySimpleUserControl.ascx");
PlaceHolder1.Controls.Add(control);
((MySimpleUserControl)control).BackColor = Color.Yellow;
...
}
<%@ OutputCache Duration="60" VaryByParam="None" %>
protected void Page_Load(object sender, EventArgs e)
{
...
Control control = LoadControl("~/MySimpleUserControl.ascx");
PlaceHolder1.Controls.Add(control);
MySimpleUserControl c = control as MySimpleUserControl;
if(c == null)
{
PartialCachingControl pc = control as PartialCachingControl;
c = pc.CachedControl as MySimpleUserControl;
}
if(c != null)
c.BackColor = Color.Yellow;
...
}
try
{
...
}
catch(Exception ex)
{
throw;
}
|
try
{
...
}
catch(Exception ex)
{
throw ex;
}
|
for(int i = GetValue(); i < GetLimit(); i++)
{
...
}
for(int i = GetValue(); i < GetLimit(); i++)
{
...
}
for(int i = GetValue(); i < GetLimit(); i++) { ... }
Test t = new Test(); t.Fun();
public class Counter : IEnumerable
{
private int i = 0;
public Counter(int i)
{
this.i = i;
}
public IEnumerator GetEnumerator()
{
while(i>0)
yield return i--;
}
}
foreach (int i in new Counter(10)) Console.WriteLine(i);
public class Counter
{
...
public IEnumerator GetEnumerator()
{
//Utworzenie enumeratora
InnerEnumerator ie = new InnerEnumerator(0);
//Ustawienie wskazania na obiekt, po którym będziemy enumerować
ie.current = this;
reutrn ie;
}
private sealed class InnerEnumerator : IEnumerator
{
//Stan w jakim znajduje się enumerator
//0 - stan początkowy
//1 - stan pośredni
//-1 - stan końcowy
private int state;
//Ostatnia wartość zwrócona przez enumerator
private int current;
//Obiekt, po którym będziemy enumerować
public Counter counter;
public InnerEnumerator(int state)
{
//Ustawienie stanu inicjalnego
this.state = state;
}
public bool MoveNext()
{
switch (this.state)
{
case 0:
//Jeśli warunek początkowy rozpoczęcia działania enumeratora
//nie będzie spełniony to przechodzimy do stanu końcowego
this.state = -1;
//Jeśli są jeszcze jakieś wartości do odwiedzenia przez enumerator
while (this.counter.i > 0)
{
//Wyznacz kolejną wartość
this.current = this.counter.i--;
//Być może są jeszcze jakieś wartości do odwiedzenia
//dlatego ustawiamy stan pośredni
this.state = 1;
return true;
LABEL:
//Jeśli nie będzie już wartości do odwiedzenia to
//należy zakończyć pracę enumeratora
this.state = -1;
}
break;
case 1:
//Kontynuujemy pracę enumeratora
goto LABEL;
}
//Enumerator odwiedził wszystkie elementy
return false;
}
public object Current
{
get{ return this.current; }
}
...
}
...
}