xtd 0.2.0
Loading...
Searching...
No Matches
generic_list_as_read_only.cpp

Shows how to use xtd::collections::generic::list class.

#include <xtd/xtd>
using namespace xtd;
using namespace xtd::collections::generic;
class example {
public:
static auto main() -> void {
auto dinosaurs = list<string> {};
console::write_line("\ncapacity: {0}", dinosaurs.capacity());
dinosaurs.add("Tyrannosaurus");
dinosaurs.add("Amargasaurus");
dinosaurs.add("Deinonychus");
dinosaurs.add("Compsognathus");
console::write_line();
for (auto dinosaur : dinosaurs)
console::write_line(dinosaur);
console::write_line("\nauto ro_dinosaurs = dinosaurs.as_read_only()");
auto ro_dinosaurs = dinosaurs.as_read_only();
console::write_line("\nElements in the read-only ilist:");
for (auto dinosaur : ro_dinosaurs)
console::write_line(dinosaur);
console::write_line("\ndinosaurs[2] = \"Coelophysis\"");
dinosaurs[2] = "Coelophysis";
console::write_line("\nElements in the read-only ilist:");
for (auto dinosaur : ro_dinosaurs)
console::write_line(dinosaur);
}
};
startup_(example::main);
// This code produces the following output :
//
//
// capacity: 0
//
// Tyrannosaurus
// Amargasaurus
// Deinonychus
// Compsognathus
//
// auto ro_dinosaurs = dinosaurs.as_read_only()
//
// Elements in the read-only ilist:
// Tyrannosaurus
// Amargasaurus
// Deinonychus
// Compsognathus
//
// dinosaurs[2] = "Coelophysis"
//
// Elements in the read-only ilist:
// Tyrannosaurus
// Amargasaurus
// Coelophysis
// Compsognathus
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10