/***********************Arrays*********************************************

//EventArgs, Convert, Environment,Console.Write, //DateTime

//List<T>, Queue<T>, SortedDictionary<TKey,TValue> //Color, Graphics, Rectangle, Brush, Font, Pen //MessageBox, DialogResult, SaveFileDialog, Timer

//

//DoWorkEventArgs, BackgroundWorker //ConnectionState

//
//Encoding, Stringbuilder
//MySqlConnection, MySqlCommand, MySqlDataReader //Directory, Filestream

//Sleep(0), Monitor, Thread, ParameterizedThreadStartpage1image708693760

int[] array1 = new int[5];
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
int[] array3 = { 1, 2, 3, 4, 5, 6 };
int[,] multiDimensionalArray1 = new int[2, 3];
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
string[] weekDays = new string[] { 
"Sun""Mon""Tue""Wed""Thu""Fri""Sat" }; int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{

System.Console.WriteLine(i); }

// *****************sort string array****************************
string[] stringArray = new string[5] { "X", "B", "Z", "Y", "A" };
Array.
Sort(stringArray);
foreach (string str in stringArray) Console.Write(str + " "); --------------------------------------------------------------------------------------------------------
User[] users = new User[3] { new User("Betty", 23), new User("Susan", 20), new User("Lisa", 25) }; Array.
Sort(users, delegate(User user1, User user2) // sort array by name

{
return user1.Name.
CompareTo(user2.Name);

// Declare a single-dimensional array
// Declare and set array element values // Alternative syntax

// Declare a two dimensional array
// Declare and set array element values

// Declare a jagged array
// Set the values of the first array in the jagged array structure

// output: A B X Y Z

// name, age

}
foreach (User user in users) Console.Write(user.Name + user.Age + " ");// write array (output: Betty23 Lisa25 Susan20) Array.
Sort(users, delegate(User user1, User user2) // sort array by age
{

return user1.Age.CompareTo(user2.Age); // (user1.Age - user2.Age)

}
foreach (User user in users) Console.Write(user.Name + user.Age + " ");// write array (output: Susan20 Betty23 Lisa25) -------------------------------------------------------------------------------------------------------
public class User : 
IComparable //The Sort method calls internally IComparable.Com-pareTo method
{

public int CompareTo(object obj) // implement IComparable interface {

if (obj is User)
{ return this.Name.
CompareTo((obj as User).Name);

}

throw new ArgumentException("Object is not a User"); }

// compare user names

}
Array.
Sort(users); // sort array of User objects// sort using IComparable implemented by User class --------------------------------------------------------------------------------------------

/***********************Arrays********************************************* //EventArgs, Convert, Environment,Console.Write, //DateTime //List<T>,... mehr erfahren »
Fenster schließen

/***********************Arrays*********************************************

//EventArgs, Convert, Environment,Console.Write, //DateTime

//List<T>, Queue<T>, SortedDictionary<TKey,TValue> //Color, Graphics, Rectangle, Brush, Font, Pen //MessageBox, DialogResult, SaveFileDialog, Timer

//

//DoWorkEventArgs, BackgroundWorker //ConnectionState

//
//Encoding, Stringbuilder
//MySqlConnection, MySqlCommand, MySqlDataReader //Directory, Filestream

//Sleep(0), Monitor, Thread, ParameterizedThreadStartpage1image708693760

int[] array1 = new int[5];
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
int[] array3 = { 1, 2, 3, 4, 5, 6 };
int[,] multiDimensionalArray1 = new int[2, 3];
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
string[] weekDays = new string[] { 
"Sun""Mon""Tue""Wed""Thu""Fri""Sat" }; int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{

System.Console.WriteLine(i); }

// *****************sort string array****************************
string[] stringArray = new string[5] { "X", "B", "Z", "Y", "A" };
Array.
Sort(stringArray);
foreach (string str in stringArray) Console.Write(str + " "); --------------------------------------------------------------------------------------------------------
User[] users = new User[3] { new User("Betty", 23), new User("Susan", 20), new User("Lisa", 25) }; Array.
Sort(users, delegate(User user1, User user2) // sort array by name

{
return user1.Name.
CompareTo(user2.Name);

// Declare a single-dimensional array
// Declare and set array element values // Alternative syntax

// Declare a two dimensional array
// Declare and set array element values

// Declare a jagged array
// Set the values of the first array in the jagged array structure

// output: A B X Y Z

// name, age

}
foreach (User user in users) Console.Write(user.Name + user.Age + " ");// write array (output: Betty23 Lisa25 Susan20) Array.
Sort(users, delegate(User user1, User user2) // sort array by age
{

return user1.Age.CompareTo(user2.Age); // (user1.Age - user2.Age)

}
foreach (User user in users) Console.Write(user.Name + user.Age + " ");// write array (output: Susan20 Betty23 Lisa25) -------------------------------------------------------------------------------------------------------
public class User : 
IComparable //The Sort method calls internally IComparable.Com-pareTo method
{

public int CompareTo(object obj) // implement IComparable interface {

if (obj is User)
{ return this.Name.
CompareTo((obj as User).Name);

}

throw new ArgumentException("Object is not a User"); }

// compare user names

}
Array.
Sort(users); // sort array of User objects// sort using IComparable implemented by User class --------------------------------------------------------------------------------------------

Filter schließen
Für die Filterung wurden keine Ergebnisse gefunden!
Zuletzt angesehen