<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.eqqon.com/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.eqqon.com/index.php?action=history&amp;feed=atom&amp;title=Ruby-like_instance_variable_syntax_in_C-Sharp</id>
		<title>Ruby-like instance variable syntax in C-Sharp - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.eqqon.com/index.php?action=history&amp;feed=atom&amp;title=Ruby-like_instance_variable_syntax_in_C-Sharp"/>
		<link rel="alternate" type="text/html" href="http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;action=history"/>
		<updated>2026-04-26T20:47:49Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=301&amp;oldid=prev</id>
		<title>Henon: /* Example: The class Range */</title>
		<link rel="alternate" type="text/html" href="http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=301&amp;oldid=prev"/>
				<updated>2007-10-30T22:38:12Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Example: The class Range&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:38, 30 October 2007&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Example: The class Range ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Example: The class Range ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Here is the Range class, a built in Ruby feature which I instantly missed the first day I started programming C# based on the Range by [http://www.codeproject.com/csharp/range.asp Goran Mitrovic]. I refactored it a bit and applied the @-notation &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;to demonstrate its clean readability&lt;/del&gt;. Those of you who love Ruby will love this style&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Here is the Range class, a built in Ruby feature which I instantly missed the first day I started programming C#&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;. It is &lt;/ins&gt;based on the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;class &lt;/ins&gt;Range by [http://www.codeproject.com/csharp/range.asp Goran Mitrovic]. I refactored it a bit and applied the @-notation. Those of you who love Ruby will love this style&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Henon</name></author>	</entry>

	<entry>
		<id>http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=299&amp;oldid=prev</id>
		<title>Henon at 21:18, 30 October 2007</title>
		<link rel="alternate" type="text/html" href="http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=299&amp;oldid=prev"/>
				<updated>2007-10-30T21:18:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:18, 30 October 2007&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[Category:CSharp]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Ruby-like instance @variables in C# ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== Ruby-like instance @variables in C# ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 192:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Category&lt;/del&gt;:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;CSharp&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;== Comments ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;If you like to comment my Blog entry, you are welcome to do so here. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;:--&lt;/ins&gt;[[&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;User&lt;/ins&gt;:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Henon|Henon&lt;/ins&gt;]] &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;22:18, 30 October 2007 (CET)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikidb_eqqon_pub:diff:version:1.11a:oldid:298:newid:299 --&gt;
&lt;/table&gt;</summary>
		<author><name>Henon</name></author>	</entry>

	<entry>
		<id>http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=298&amp;oldid=prev</id>
		<title>Henon: New page: == Ruby-like instance @variables in C# ==  Although I am very impressed by C#, Ruby is still my favorite programming language because of it's clean design and unre...</title>
		<link rel="alternate" type="text/html" href="http://www.eqqon.com/index.php?title=Ruby-like_instance_variable_syntax_in_C-Sharp&amp;diff=298&amp;oldid=prev"/>
				<updated>2007-10-30T21:09:11Z</updated>
		
		<summary type="html">&lt;p&gt;New page: == Ruby-like instance @variables in C# ==  Although I am very impressed by &lt;a href=&quot;/index.php/Category:CSharp&quot; title=&quot;Category:CSharp&quot;&gt;C#&lt;/a&gt;, &lt;a href=&quot;/index.php/Ruby&quot; title=&quot;Ruby&quot;&gt;Ruby&lt;/a&gt; is still my favorite programming language because of it&amp;#39;s clean design and unre...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Ruby-like instance @variables in C# ==&lt;br /&gt;
&lt;br /&gt;
Although I am very impressed by [[:Category:CSharp|C#]], [[Ruby]] is still my favorite programming language because of it's clean design and unreached flexibility. One of the things I like about Ruby is its way to mark '''instance variables''' (in Ruby's terminology) or '''member variables / fields''' (in C# terminology). They are prefixed with the @-sign. This makes code very easy to read. To get the same effect most C# programmers rely on a kind of [http://www.worldwidewords.org/articles/hungary.htm Hungarian style notation] which means prefixing with ''m_''. Today I discovered that the C# compiler allows the @-sign as prefix for identifiers. This is useful if you need to name an identifier e.g. a variable like a keyword. How often have I been forced to unwillingly name variables which contain a class-object ''klass'' or ''_class'' when programming in Ruby. So this is really a nice feature of C#, isn't it?&lt;br /&gt;
&lt;br /&gt;
Even better, the @-prefix can also be used to mark member variables in C#. Since I am virulently against the Hungarian notation for variable names (e.g. ''lpSzFile'') this is exactly what I was looking for. Now programming C# feels much more like Ruby for me. There are still many oddities in C# which I need to get used to or even better I need to overcome by using the new ''extension methods'' introduced by C# 3.0. &lt;br /&gt;
&lt;br /&gt;
== Example: The class Range ==&lt;br /&gt;
Here is the Range class, a built in Ruby feature which I instantly missed the first day I started programming C# based on the Range by [http://www.codeproject.com/csharp/range.asp Goran Mitrovic]. I refactored it a bit and applied the @-notation to demonstrate its clean readability. Those of you who love Ruby will love this style.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
namespace Eqqon&lt;br /&gt;
{&lt;br /&gt;
    public struct Range : ICollection, IEnumerable&lt;br /&gt;
    {&lt;br /&gt;
        public Range(int startValue, int endValue)&lt;br /&gt;
        {&lt;br /&gt;
            @start = startValue;&lt;br /&gt;
            @end = 0;&lt;br /&gt;
            this.End = endValue;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public Range(ICollection col)&lt;br /&gt;
        {&lt;br /&gt;
            @start = 0;&lt;br /&gt;
            @end = ((col != null) ? col.Count : 0) - 1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int Start&lt;br /&gt;
        {&lt;br /&gt;
            get { return @start; }&lt;br /&gt;
            set&lt;br /&gt;
            {&lt;br /&gt;
                @start = value;&lt;br /&gt;
                if (@end &amp;lt; (@start - 1)) @end = @start - 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int End&lt;br /&gt;
        {&lt;br /&gt;
            get { return @end; }&lt;br /&gt;
            set&lt;br /&gt;
            {&lt;br /&gt;
                @end = (value &amp;gt;= @start) ? value : (@start - 1);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int Mid&lt;br /&gt;
        {&lt;br /&gt;
            get&lt;br /&gt;
            {&lt;br /&gt;
                return (@start + @end) / 2;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void Set(int start, int end)&lt;br /&gt;
        {&lt;br /&gt;
            @start = start;&lt;br /&gt;
            this.End = end;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public bool Contains(int value)&lt;br /&gt;
        {&lt;br /&gt;
            return (@start &amp;lt;= value) &amp;amp;&amp;amp; (value &amp;lt;= @end);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static bool Contains(int left, int value, int right)&lt;br /&gt;
        {&lt;br /&gt;
            return (left &amp;lt;= value) &amp;amp;&amp;amp; (value &amp;lt;= right);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int Saturate(int value)&lt;br /&gt;
        {&lt;br /&gt;
            return (value &amp;gt; @start) ? ((value &amp;lt; @end) ? value : @end) : @start;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static int Saturate(int left, int value, int right)&lt;br /&gt;
        {&lt;br /&gt;
            return (value &amp;gt; left) ? ((value &amp;lt; right) ? value : right) : left;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static Range operator &amp;amp;(Range r1, Range r2)&lt;br /&gt;
        {&lt;br /&gt;
            return new Range(Math.Max(r1.Start, r2.Start), Math.Min(r1.End, r2.End));&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static Range operator |(Range r1, Range r2)&lt;br /&gt;
        {&lt;br /&gt;
            return new Range(Math.Min(r1.Start, r2.Start), Math.Max(r1.End, r2.End));&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void Offset(int o)&lt;br /&gt;
        {&lt;br /&gt;
            @start += o;&lt;br /&gt;
            @end += o;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void Resize(int s)&lt;br /&gt;
        {&lt;br /&gt;
            End += s;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int Count&lt;br /&gt;
        {&lt;br /&gt;
            get { return @end - @start + 1; }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public bool Empty&lt;br /&gt;
        {&lt;br /&gt;
            get { return @end == (@start - 1); }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public int this[int index]&lt;br /&gt;
        {&lt;br /&gt;
            get&lt;br /&gt;
            {&lt;br /&gt;
                if (Count == 0) throw new InvalidOperationException(&amp;quot;Cannot perform this operation on a Range with Count 0!&amp;quot;);&lt;br /&gt;
                return @start + index % Count;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public void CopyTo(Array array, int index)&lt;br /&gt;
        {&lt;br /&gt;
            if (array == null) throw new ArgumentNullException(&amp;quot;Array must not be null!&amp;quot;);&lt;br /&gt;
            if (index &amp;lt; 0) throw new ArgumentOutOfRangeException(&amp;quot;index&amp;quot;, index, &amp;quot;Index must not be &amp;lt; 0&amp;quot;);&lt;br /&gt;
            if (array.Rank != 1) throw new ArgumentException(&amp;quot;Array must not be multidimensional.&amp;quot;, &amp;quot;array&amp;quot;);&lt;br /&gt;
            if (!new Range(array).Contains(index)) throw new ArgumentOutOfRangeException(&amp;quot;index&amp;quot;);&lt;br /&gt;
            if (Count == 0) return;&lt;br /&gt;
            if (!new Range(array).Contains(index + Count - 1)) throw new ArgumentOutOfRangeException(&amp;quot;index&amp;quot;);&lt;br /&gt;
            foreach (int i in this)&lt;br /&gt;
            {&lt;br /&gt;
                array.SetValue(i, index + i - @start);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public bool IsSynchronized&lt;br /&gt;
        {&lt;br /&gt;
            get { return false; }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public object SyncRoot&lt;br /&gt;
        {&lt;br /&gt;
            get { return this; }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public IEnumerator GetEnumerator()&lt;br /&gt;
        {&lt;br /&gt;
            return new Iterator(ref this);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        private class Iterator : IEnumerator&lt;br /&gt;
        {&lt;br /&gt;
            public Iterator(ref Range r)&lt;br /&gt;
            {&lt;br /&gt;
                @range = r;&lt;br /&gt;
                Reset();&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            public object Current&lt;br /&gt;
            {&lt;br /&gt;
                get&lt;br /&gt;
                {&lt;br /&gt;
                    if (!@range.Contains(@pos + @range.Start)) throw new InvalidOperationException();&lt;br /&gt;
                    return @range[@pos];&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            public bool MoveNext()&lt;br /&gt;
            {&lt;br /&gt;
                return @range.Contains((++@pos) + @range.Start);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            public void Reset()&lt;br /&gt;
            {&lt;br /&gt;
                @pos = -1;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            private Range @range;&lt;br /&gt;
            private int @pos;&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        private int @start;&lt;br /&gt;
        private int @end;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:CSharp]]&lt;/div&gt;</summary>
		<author><name>Henon</name></author>	</entry>

	</feed>