#24 edit mode for C#

open
nobody
None
5
2004-07-13
2004-07-13
wayne
No

Provide a mode for C#, an ECMA standard language (I
assume). The java mode is very close but there are
several language elements that don't render correctly,
such as property and indexer routines.

// These act like a field in a java class.
// Property example
public bool IsDeleteAllowed{
get{
return !IsEmptyItem && _deleteAllowed;
}
set{
_deleteAllowed = value;
}
}
// usage

myObject.IsDeleteAllowed = true;

if(myObject.IsDeleteAllowed){
// delete is allowed
}

// Indexer
/* comment taken from
http://msdn.microsoft.com/library/en-
us/csref/html/vcerrUsingIndexers.asp?frame=true
Indexers permit instances of a class or struct to be
indexed in the same way as arrays. Indexers are similar
to properties except that their accessors take
parameters.

*/
// Implementing the interface.
class IndexerClass : IMyInterface
{
private int [] myArray = new int[100];
public int this [int index] // indexer declaration
{
get
{
// Check the index limits.
if (index < 0 || index >= 100)
return 0;
else
return myArray[index];
}
set
{
if (!(index < 0 || index >= 100))
myArray[index] = value;
}
}
}

public class MainClass
{
public static void Main()
{
IndexerClass b = new IndexerClass();
// Call the indexer to initialize the elements #3 and
#5.
b[2] = 4;
b[5] = 32;
for (int i=0; i<=10; i++)
{
Console.WriteLine("Element #{0} = {1}", i, b[i]);
}
}
}

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks