softversko inŽenjerstvo 1 – skripta za veŽe … softversko inzenjers… · softversko...
TRANSCRIPT
-
SOFTVERSKO INENJERSTVO 1 SKRIPTA ZA VEBE (radna verzija) Autori: Doc dr Ljubica Kazi, prof. dr Dragica Radosav SADRAJ: I DEO OSNOVE 1. OBLAST UML PROVERA ZNANJA: grupni rad (dokumentovanje softvera) 2. OBLAST C# sintaksa 3. OBLAST OBJEKTNO ORJENTISANO PROGRAMIRANJE u C# PROVERA ZNANJA: Test poznavanja osnovnih pojmova II DEO RAZVOJ APLIKACIJA 4. OBLAST KLASE ZA RAD SA PODACIMA BAZA PODATAKA, TEKSTUALNE DATOTEKE, XML, FILE/FOLDER 5. OBLAST RAZVOJ WINDOWS I WEB APLIKACIJA 6. OBLAST RAZVOJ VIESLOJNE APLIKACIJE PROVERA ZNANJA: 1. KOLOKVIJUM 7. OBLAST MVC PRISTUP I ENTITY FRAMEWORK PROVERA ZNANJA: 2. KOLOKVIJUM PROVERA ZNANJA - OBAVEZNI SEMINARSKI RAD: OBJEDINJENA PRIMENA CELOKUPNOG ZNANJA III DEO NAPREDNE TEHNIKE informativno ovde, detaljnije: SOFTVERSKO INZENJERSTVO 2 7. DESIGN GUIDELINES uputstva za pravilno osmiljavanje klasa 8. DESIGN PATTERNS abloni opteprihvaenih industrijskih reenja klasa 9. REFACTORING reorganizovanje koda radi unapreenja kvaliteta koda (itljivosti, brzine rada, fleksibilnosti) ----------------------- 10. KONKURENTNO PROGRAMIRANJE niti, sinhronizacija OSNOVNA TROSLOJNA ARHITEKTURA
PREZENTACIONI SLOJ KORISNICKI INTERFEJS = WINDOWS APP, WEB APP, MOBILNA APP
SLOJ POSLOVNE LOGIKE BIBLIOTEKE KLASA (DLL) ILI WEB SERVISI VIESLOJNI PRISTUP VIE BIBLIOTEKA KLASA SA PODELOM ZADUENJA
SLOJ PODATAKA BAZA PODATAKA, XML FAJLOVI, JSON FAJLOVI, EXCEL FAJLOVI.
LITERATURA: OSNOVNI DEO I RAZVOJ APLIKACIJA: 1. Grady Booch, James Rumbaugh, Ivar Jacobson: The Unified Modeling Language User Guide,Addison-Wesley, 1999. 2. Robin A. Reynolds Haertle: OOP sa Microsoft tehnologijama Visual Basic.NET I Visual C#. NET, CET, 2002. 3. Jesse Liberty: Programiranje na jeziku C#, Mikro knjiga, 2007. 4. Microsoft: Programming with C#, MSDN training workbook, Microsoft, 2002. NAPREDNI DEO: 1. Arthur J. Riel: Heuristike objektno-orjentisanog dizajna, CET, 2003. 2. Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides: Design Patterns, Addison-Wesley, 1995. 3. Martin Fowler: Refactoring Improving the Design of Existing Code, Addison-Wesley, 1999.
-
1. OBLAST UML Teorija
Case alat
Primer UML dijagrama sa vebi
Generisanje programskog koda biblioteke klasa na osnovu modela u okviru CASE alata
Teorija UML (Unified Modeling Language) predstavlja prvenstveno grafiki jezik modelovanja u svim fazama razvoja softvera, poev od specifikacije zahteva, sistemske analize, dizajna, dokumentovanja itd. Najea primena UML je u specifikaciji zahteva korisnika (use case dijagram) i dizajnu (dijagram komponenti, dijagram razmetaja, dijagram klasa). Prva verzija UML 1.0 ukljuuje 9 vrsta dijagrama: use case dijagram, class dijagram, object dijagram, sequence dijagram, communication dijagram, activity dijagram, statechart dijagram, dijagram komponenti (component), dijagram razmetaja (deployment). Druga verzija UML (UML 2.0) ukljuuje Package dijagram, interaction overview, composite structure.
Use case diagram (Dijagram sluajeva korienja) Namena: prikaz osnovnih funkcija koju sistem nudi korisniku, sa aspekta vrednosti ili radnih aktivnosti koje sistem reava. Elementi: actor (profil korisnika), sluaj korienja, veze izmeu actora I sluaja korienja, veze izmeu samih sluajeva korienja. Pored samog dijagrama, radi detaljnijeg opisa koriste se I specifikacije pojedinih sluajeva korienja koje obuhvataju: preduslove (potrebno stanje sistema pre poetka rada sluaja korienja), postuslove (rezultate rada), action steps (ukljuuje pseudokod opisa interakcije korisnika I sistema uz razliite scenarije), exceptions (obrada greaka), extension points (take proirenja na druge sluajeve korienja).
Component diagram (Dijagram komponenti) Namena: predstavlja osnovne elemente softverskog sistema I njihove meusobne zavisnosti, Elementi: paketi, komponente, fajlovi, veze zavisnosti
Deployment diagram (Dijagram razmetaja) Namena: predstavlja raspored softverskih komponenti po vorovima (serverima) u raunarskoj mrei (iako se pod pojmom server podrazumeva zapravo raunarski program koji obavlja odreeni servis obradu i fiziki sve te komponente: serveri i ostale komponente softvera mogu biti na jednom raunaru), elementi: vorovi, softverske komponente, veze zavisnosti
Class diagram (Dijagram klasa) Namena: predstavlja klase softverskog reenja i njihove zavisnosti, Elementi: Klase (atributi, metode), veze izmeu klasa (asocijacija, agregacija, kompozicija, nasleivanje). Kod opisa klasa bitno je podesiti modifikatore pristupa na nivou klase, atributa I metoda (private, public, protected, internal). Kod atributa vano je podesiti naziv I tip. Bitno je razlikovati sutinske attribute polja (promenljive u okviru klase koje kod konkretnog objekta uvaju vrednosti) i svojstva (javno dostupne predstavnike polja samo za ona polja koja elimo da budu javno dostupna I to se realizuje putem get-set metoda). Obratiemo panju na veliinu slova u nazivima atributa, metoda I parametara metoda (camelCasing prvo slovo malo, ostala prva slova reci velika,a ostala mala: privatni atributi (polja), parametri metoda, promenljive deklarisane unutar metoda; PascalCasing Svako prvo slovo reci je veliko, ostala mala: naziv klase, metode). Zaglavlje metode (naziv I lista parametara) naziva se signature (potpis) metode. Kod parametara metoda obratiemo panju da li su ulazni, izlazni ili ulazno-izlazni. Kod podeavanja karakteristika veza, bitno je u CASE alatu pravilno podesiti tip veze i osobine Navigable i Container Type.
Sequence diagram (Dijagram sekvenci) Namena: predstavlja vremenski sled komunikacije objekata klasa u realizaciji jednog sluaja korienja (odnosno jednog scenarija u okviru jednog sluaja korienja). Elementi: actor (moe biti ovek ili drugi automatizovani-softverski sistem), objekti klasa, poruke (pozivi metoda klasa), aktivacija (vertikalni pravougaonik kojim se predstavlja duina trajanja ivota jednog objekta, odnosno interacije putem razmene poruka).
Ostale vrste dijagrama:
Object diagram predstavlja objekte klasa sa konkretnim vrednostima atributa radi ilustracije I objanjenja znaenja klasa
State chart diagram predstavlja razliita stanja koje objekat jedne klase moe da ima. Stanje objekta odreeno je vrednostima njegovih atributa u svakom trenutku.
Communication diagram slino dijagramu sekvenci, predstavlja objekte klasa i razmenu poruka, bez prikaza vremenske dimenzije toka razmene poruka (prikazuje se samo redni broj poruke).
-
Activity diagram - moe se koristiti u fazi specifikacije toka poslovnih procesa (sistemska analiza), predstavljanju action steps kod specifikacije jednog sluaja korienja ili predstavljanju naina realizacije neke metode jedne klase.
CASE Alat U okviru razvoja softvera radi povezivanja razliitih faza razvoja, ubrzavanja I poveanja kvaliteta, koriste se posebni alati CASE (Computer Aided Software Engineering) alati. Najee ukljuuju u sebe vie alata koji mogu da razmenjuju podatke rezultata, kako bi naredna faza razvoja mogla efikasnije da se nastavi. Tako se na osnovu jedne vrste modela mogu generisati druge vrste modela ili ak upotrebljivi elementi prototipa reenja: s jedne strane baze podataka, s druge strane izvorni kod programa. U okviru CASE alata Sybase Power Designer, u primeni UML modela koristi se Object Oriented Model, gde se moe birati univerzalni-apstraktni objektni jezik Analysis ili konkretan programski jezik (npr. C#), kao I razliite vrste dijagrama.
PRIMER UML DIJAGRAMA SA VEBI Analiziran je primer aplikacije koja ukljuuje 2 nezavisna projekta koji mogu biti smeteni I aktivni na razliitim raunarima na Internetu: ASPX web aplikaciju i Web servis (SOAP/XML) , ime se ilustruje aktuelni pristup razvoju softvera: servisno-orjentisana arhitektura, tj. razvoj softvera kao servis (Software as service). Navedeni pristup se zasniva na konceptu da jedna firma ne mora da razvija kompletan softver, ve koristi usluge (besplatno ili plaa) realizovanog I javno dostupnog softvera druge firme putem interneta (pozivanjem odgovarajueg URL gde se nalazi navedeni softverski servis). U toku izvravanja softvera navedene firme, u odreenom trenutku se poziva softverska funkcija udaljenog servisa, izvrava I dobija rezultat rada, a zatim navedeni softver dalje nastavlja sa radom. U okviru dokumentovanja postojeeg softverskog reenja realizovani su sledei dijagrami: USE CASE DIJAGRAM
-
DIJAGRAM KLASA
DIJAGRAM KOMPONENTI
DIJAGRAM RAZMETAJA
-
DOPUNJENI DIJAGRAM KLASA
DIJAGRAM SEKVENCI
0..1
0..*
0..1
0..*
_Default
- prezime : String
-
-
#
#
NapuniCombo ()
SnimiPodatke (String brojIndeksa, String prezime, String ime, String nazivSmera)
Page_Load (object sender, EventArgs e)
btnSnimi_Click (object sender, EventArgs e)
: void
: boolean
: void
: void
Service1
+
+
+
DajSifruSmera (String nazivSmera)
DajDataSetSmerovi ()
DajNazivStavkeIzRb (int redniBrojStavke)
: String
: DataSet
: String
System.Web.UI.Page
System.Web.Services.WebService
RAcun
Stavke racuna
MEsto
-
-
ptt
nazivMesta
: String
: String
-
GENERISANJE PROGRAMSKOG KODA BIBLIOTEKE KLASA NA OSNOVU MODELA U OKVIRU CASE ALATA SLOJ KLASA 1. Kreirati CDM model. Racun -(1:M dependent) - stavke - roba Racun - kupac Kupac is a firma, osoba.
SequenceDiagram_1
Sifra smera
DajSifruSmera
Izbor opcije za snimanje podataka
Unos podataka u text boxove
Ucitavanje stranice
Stranica za unos
objKlasaSmer
Korisnik web aplikacije
Sifra smera
DajSifruSmera
Izbor opcije za snimanje podataka
Unos podataka u text boxove
Ucitavanje stranice
-
2. Generisati dijagram klasa iz CDM modela (Tools Generate object oriented model). Podesiti karakteristike relacija: - asocijacija (obicna relacija) podesiti Navigable, ukloniti ArrayList ako ima. - nasledjivanje (od is-a) - kompozicija (celina - deo) Dodati set/get metode.
Redni broj stavke brisemo,
pravimo slozeni primarni
kljuc od broja racuna
i oznake robe.
Tip kupca
je dobio
sadrzi
je izabrana
JEDNINA U
NAZIVU
SVAKOG
ENTITETA!!!
Racun
BrojRacuna
Datum
UkupanIznos
Variable characters (20)
Date
Float
Identifier_1
Kupac
IDKupca
Adresa
Telefon
Email
Long integer
Variable characters (100)
Variable characters (50)
Variable characters (50)
Identifier_1
Firma
NazivFirme Variable characters (100)Osoba
Prezime
Ime
Variable characters (50)
Variable characters (40)
Stavka racuna
Kolicina Float
Roba
OznakaRobe
NazivRobe
Cena
JedinicaMere
Variable characters (10)
Variable characters (100)
Float
Variable characters (30)
Identifier_1
-
3. Iz dijagrama klasa generisati C# kod biblioteke klasa.
1..1
0..*
1..1
1..*
1..1
0..*
Racun
-
-
-
+
+
+
pBrojRacuna
pDatum
pUkupanIznos
BrojRacuna
Datum
UkupanIznos
: string
: DateTime
: float
: string
: DateTime
: float
+
+
+
+
+
+
set_BrojRacuna (string value)
get_BrojRacuna ()
set_Datum (DateTime value)
get_Datum ()
set_UkupanIznos (float value)
get_UkupanIznos ()
: void
: string
: void
: DateTime
: void
: float
Kupac
-
-
-
-
+
+
+
+
pIDKupca
pAdresa
pTelefon
pEmail
IDKupca
Adresa
Telefon
Email
: long
: string
: string
: string
: long
: string
: string
: string
+
+
+
+
+
+
+
+
set_IDKupca (long value)
get_IDKupca ()
set_Adresa (string value)
get_Adresa ()
set_Telefon (string value)
get_Telefon ()
set_Email (string value)
get_Email ()
: void
: long
: void
: string
: void
: string
: void
: string
Firma
-
+
pNazivFirme
NazivFirme
: string
: string
+
+
set_NazivFirme (string value)
get_NazivFirme ()
: void
: string
Osoba
-
-
+
+
pPrezime
pIme
Prezime
Ime
: string
: string
: string
: string
+
+
+
+
set_Prezime (string value)
get_Prezime ()
set_Ime (string value)
get_Ime ()
: void
: string
: void
: string
Stavka racuna
-
+
pKolicina
Kolicina
: float
: float
+
+
set_Kolicina (float value)
get_Kolicina ()
: void
: float
Roba
-
-
-
-
+
+
+
+
pOznakaRobe
pNazivRobe
pCena
pJedinicaMere
OznakaRobe
NazivRobe
Cena
JedinicaMere
: string
: string
: float
: string
: string
: string
: float
: string
+
+
+
+
+
+
+
+
set_OznakaRobe (string value)
get_OznakaRobe ()
set_NazivRobe (string value)
get_NazivRobe ()
set_Cena (float value)
get_Cena ()
set_JedinicaMere (string value)
get_JedinicaMere ()
: void
: string
: void
: string
: void
: float
: void
: string
-
OBICNA KLASA, GET I SET ZA REALIZACIJU PROPERTY public class Roba { private string POznakaRobe; private string PNazivRobe; private float PCena; private string PJedinicaMere; public string OznakaRobe { get { return POznakaRobe; } set { if (this.POznakaRobe != value) this.POznakaRobe = value; } }
Objasnjenje za sva 3 najvaznija tipa veze sa dijagrama klasa KAKO SE TO REALIZUJE U KODU: NASLEDJIVANJE public class Osoba : Kupac ASOCIJACIJA public class StavkaRacuna { public Roba roba; private float PKolicina; KOMPOZICIJA public class Racun { public System.Collections.ArrayList stavkaRacuna; public void AddStavkaRacuna(StavkaRacuna newStavkaRacuna) { ..
-
public void RemoveStavkaRacuna(StavkaRacuna oldStavkaRacuna) {
Dodati namespace DODAJEMO UZ NAZIV PROJEKTA ZA SVAKU KLASU, DA BI BILA UKLJUCENA U PROJEKAT I VIDLJIVA SPOLJA KAO DEO BIBLIOTEKE KLASA.
Generisati dll (Dynamic Link Library).
PREZENTACIONI SLOJ
1. KREIRATI KORISNICKI INTERFEJS WINDOWS APLIKACIJE sa formom za unos podataka o robi: OZNAKA, NAZIV, CENA, JEDINICA MERE, Tasteri za navigaciju: PRVI, PRETHODNI, SLEDECI, POSLEDNJI , Tasteri za azuriranje: UNOS, BRISANJE, IZMENA, SNIMI, ODUSTANI Povezati korisnicki interfejs sa kreiranom bibliotekom DLL.
-
2. OBLAST C# SINTAKSA OSNOVE SINTAKSE
Komentari
// za svaki red ili /* */ za blok
Na kraju svake naredbe ;
Case sensitive nije isto naziv i Naziv
Oblast { }, Oblast vaenja promenljivih, poetak I kraj bloka naredbi, poetak I kraj metode, klase, namespace TIPOVI PODATAKA prosti, Standardni - strukture - promenljive tipa vrednosti (promenljiva ukazuje direktno na lokaciju gde se nalaze podaci): Integer, real, bool, enum, struct promenljive tipa reference (promenljiva sadrzi pokazivac na memorijsku lokaciju gde se nalaze podaci): klasa, interfejs, niz, string, objekat, delegat The variables in C#, are categorized into the following types:
Value types
Reference types Pointer types
Value Type Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value. The following table lists the available value types in C# 2010:
Type Represents Range Default Value
bool Boolean value True or False False
byte 8-bit unsigned integer 0 to 255 0
char 16-bit Unicode character U +0000 to U +ffff '\0'
decimal 128-bit precise decimal values with 28-29 significant digits
(-7.9 x 1028
to 7.9 x 1028
) / 100 to 28
0.0M
double 64-bit double-precision floating point type (+/-)5.0 x 10-324
to (+/-)1.7 x 10308
0.0D
float 32-bit single-precision floating point type -3.4 x 1038
to + 3.4 x 1038
0.0F
int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0
long 64-bit signed integer type -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
0L
sbyte 8-bit signed integer type -128 to 127 0
short 16-bit signed integer type -32,768 to 32,767 0
uint 32-bit unsigned integer type 0 to 4,294,967,295 0
ulong 64-bit unsigned integer type 0 to 18,446,744,073,709,551,615 0
ushort 16-bit unsigned integer type 0 to 65,535 0
To get the exact size of a type or a variable on a particular platform, you can use the sizeof method. The expression sizeof(type) yields the storage size of the object or type in bytes. Following is an example to get the size of int type on any machine:
using System; namespace DataTypeApplication
-
{ class Program { static void Main(string[] args) { Console.WriteLine("Size of int: {0}", sizeof(int)); Console.ReadLine(); } } } When the above code is compiled and executed, it produces the following result:
Size of int: 4 Reference Type The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables. In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.
Object Type The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class. The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion. When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.
object obj; obj = 100; // this is boxing Dynamic Type You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time. Syntax for declaring a dynamic type is:
dynamic = value; For example,
dynamic d = 20; Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.
String Type The String Type allows you to assign any string values to a variable. The string type is an alias for the System.String class. It is derived from object type. The value for a string type can be assigned using string literals in two forms: quoted and @quoted. For example,
String str = "Tutorials Point"; A @quoted string literal looks as follows:
@"Tutorials Point"; The user-defined reference types are: class, interface, or delegate. We will discuss these types in later chapter.
Pointer Type Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as the pointers in C or C++. Syntax for declaring a pointer type is:
type* identifier; For example,
char* cptr;
int* iptr;
Razlikovati string i String. String je klasa , System.String Properties
Name Description
Chars[Int32] Gets the Char object at a specified position in the current String object.
Length Gets the number of characters in the current String object.
Methods
Name Description
Clone() Returns a reference to this instance of String.
Compare(String, Int32, String, Int32, Int32)
Compares substrings of two specified String objects and returns an integer that indicates their relative
position in the sort order.
Compare(String, Int32, String, Int32, Compares substrings of two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.
https://msdn.microsoft.com/en-us/library/system.string.chars(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.char(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.length(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.clone(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/x7tax739(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/x7tax739(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1e058ek8(v=vs.110).aspx
-
Int32, Boolean)
Compare(String, Int32, String, Int32, Int32, Boolean, CultureInfo)
Compares substrings of two specified String objects, ignoring or honoring their case and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position
in the sort order.
Compare(String, Int32, String, Int32, Int32, CultureInfo, CompareOptions)
Compares substrings of two specified String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the
two substrings to each other in the sort order.
Compare(String, Int32, String, Int32, Int32, StringComparison)
Compares substrings of two specified String objects using the specified rules, and returns an integer that
indicates their relative position in the sort order.
Compare(String, String) Compares two specified String objects and returns an integer that indicates their relative position in the sort order.
Compare(String, String, Boolean) Compares two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.
Compare(String, String, Boolean, CultureInfo)
Compares two specified String objects, ignoring or honoring their case, and using culture-specific
information to influence the comparison, and returns an integer that indicates their relative position in the sort
order.
Compare(String, String, CultureInfo, CompareOptions)
Compares two specified String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two
strings to each other in the sort order.
Compare(String, String, StringComparison)
Compares two specified String objects using the specified rules, and returns an integer that indicates their
relative position in the sort order.
CompareOrdinal(String, Int32, String, Int32, Int32)
Compares substrings of two specified String objects by evaluating the numeric values of the
corresponding Char objects in each substring.
CompareOrdinal(String, String) Compares two specified String objects by evaluating the numeric values of the corresponding Charobjects in each string.
CompareTo(Object) Compares this instance with a specified Object and indicates whether this instance precedes, follows, or
appears in the same position in the sort order as the specified Object.
CompareTo(String) Compares this instance with a specified String object and indicates whether this instance precedes, follows,
or appears in the same position in the sort order as the specified string.
Concat(IEnumerable) Concatenates the members of a constructed IEnumerable collection of type String.
Concat(Object) Creates the string representation of a specified object.
Concat(Object, Object) Concatenates the string representations of two specified objects.
Concat(Object, Object, Object) Concatenates the string representations of three specified objects.
Concat(Object, Object, Object, Object) Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list.
Concat(Object[]) Concatenates the string representations of the elements in a specified Object array.
Concat(String, String) Concatenates two specified instances of String.
https://msdn.microsoft.com/en-us/library/3h045cx3(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/3h045cx3(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/cc190416(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/cc190416(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/7aaf32ef(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/7aaf32ef(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/84787k22(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/zkcaxw5y(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/hyxc48dt(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/hyxc48dt(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/cc190529(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/cc190529(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/e6883c06(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/e6883c06(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/es986b3k(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/es986b3k(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.char(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/af26w0wa(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.char(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/fkw3h78a(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/35f0x18w(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dd784338(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/9eekhta0(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/khca9w90(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/kbseaaft(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/f8z7w96s(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/4ewx19dc(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/k9c94ey1(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/a6d350wd(v=vs.110).aspx
-
Concat(String, String, String) Concatenates three specified instances of String.
Concat(String, String, String, String) Concatenates four specified instances of String.
Concat(String[]) Concatenates the elements of a specified String array.
Concat(IEnumerable) Concatenates the members of an IEnumerable implementation.
Contains(String) Returns a value indicating whether a specified substring occurs within this string.
Copy(String) Creates a new instance of String with the same value as a specified String.
CopyTo(Int32, Char[], Int32, Int32) Copies a specified number of characters from a specified position in this instance to a specified position in an
array of Unicode characters.
EndsWith(String) Determines whether the end of this string instance matches the specified string.
EndsWith(String, Boolean, CultureInfo) Determines whether the end of this string instance matches the specified string when compared using the
specified culture.
EndsWith(String, StringComparison) Determines whether the end of this string instance matches the specified string when compared using the
specified comparison option.
Equals(Object) Determines whether this instance and a specified object, which must also be a String object, have the same
value.(Overrides Object.Equals(Object).)
Equals(String) Determines whether this instance and another specified String object have the same value.
Equals(String, String) Determines whether two specified String objects have the same value.
Equals(String, String, StringComparison) Determines whether two specified String objects have the same value. A parameter specifies the culture, case, and sort rules used in the comparison.
Equals(String, StringComparison) Determines whether this string and a specified String object have the same value. A parameter specifies the
culture, case, and sort rules used in the comparison.
Format(IFormatProvider, String, Object) Replaces the format item or items in a specified string with the string representation of the corresponding object. A parameter supplies culture-specific formatting information.
Format(IFormatProvider, String, Object, Object)
Replaces the format items in a specified string with the string representation of two specified objects. A
parameter supplies culture-specific formatting information.
Format(IFormatProvider, String, Object, Object, Object)
Replaces the format items in a specified string with the string representation of three specified objects. An parameter supplies culture-specific formatting information.
Format(IFormatProvider, String, Object[]) Replaces the format items in a specified string with the string representations of corresponding objects in a specified array. A parameter supplies culture-specific formatting information.
Format(String, Object) Replaces one or more format items in a specified string with the string representation of a specified object.
Format(String, Object, Object) Replaces the format items in a specified string with the string representation of two specified objects.
Format(String, Object, Object, Object) Replaces the format items in a specified string with the string representation of three specified objects.
https://msdn.microsoft.com/en-us/library/5e285t1h(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/0eafbze3(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/0wkb0y3w(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dd991828(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/9eekhta0(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.copy(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.copyto(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/2333wewz(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/t9h2fbth(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131430(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/fkfd9eh8(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/bsc2ak47(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/858x0yyx(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1hkt4325(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/t4411bks(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/c64xh8f9(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dn906224(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dn906223(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dn906223(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dn906221(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dn906221(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1ksz8yb7(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/fht0f5be(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/zf3d0ccc(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/d9t40k6d(v=vs.110).aspx
-
Format(String, Object[]) Replaces the format item in a specified string with the string representation of a corresponding object in a specified array.
GetEnumerator() Retrieves an object that can iterate through the individual characters in this string.
GetHashCode() Returns the hash code for this string.(Overrides Object.GetHashCode().)
GetType() Gets the Type of the current instance.(Inherited from Object.)
GetTypeCode() Returns the TypeCode for class String.
IndexOf(Char) Reports the zero-based index of the first occurrence of the specified Unicode character in this string.
IndexOf(Char, Int32) Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The
search starts at a specified character position.
IndexOf(Char, Int32, Int32) Reports the zero-based index of the first occurrence of the specified character in this instance. The search
starts at a specified character position and examines a specified number of character positions.
IndexOf(String) Reports the zero-based index of the first occurrence of the specified string in this instance.
IndexOf(String, Int32) Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts
at a specified character position.
IndexOf(String, Int32, Int32) Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts
at a specified character position and examines a specified number of character positions.
IndexOf(String, Int32, Int32, StringComparison)
Reports the zero-based index of the first occurrence of the specified string in the current String object. Parameters specify the starting search position in the current string, the number of characters in the current
string to search, and the type of search to use for the specified string.
IndexOf(String, Int32, StringComparison) Reports the zero-based index of the first occurrence of the specified string in the current String object.
Parameters specify the starting search position in the current string and the type of search to use for the specified string.
IndexOf(String, StringComparison) Reports the zero-based index of the first occurrence of the specified string in the current String object. A
parameter specifies the type of search to use for the specified string.
IndexOfAny(Char[]) Reports the zero-based index of the first occurrence in this instance of any character in a specified array of
Unicode characters.
IndexOfAny(Char[], Int32) Reports the zero-based index of the first occurrence in this instance of any character in a specified array of
Unicode characters. The search starts at a specified character position.
IndexOfAny(Char[], Int32, Int32) Reports the zero-based index of the first occurrence in this instance of any character in a specified array of
Unicode characters. The search starts at a specified character position and examines a specified number of character positions.
Insert(Int32, String) Returns a new string in which a specified string is inserted at a specified index position in this instance.
Intern(String) Retrieves the system's reference to the specified String.
IsInterned(String) Retrieves a reference to a specified String.
IsNormalized() Indicates whether this string is in Unicode normalization form C.
IsNormalized(NormalizationForm) Indicates whether this string is in the specified Unicode normalization form.
https://msdn.microsoft.com/en-us/library/b1csw23d(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.getenumerator(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.gethashcode(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object.gethashcode(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object.gettype(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.type(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.gettypecode(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.typecode(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/kwb0bwyd(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/5xkyx09y(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131434(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/7cct0x33(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/d93tkzah(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224423(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224423(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224424(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224425(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/11w09h50(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/56y4ddbk(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/6wh7x3fs(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.insert(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.intern(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.isinterned(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/0wcxb622(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/kcy08ww5(v=vs.110).aspx
-
IsNullOrEmpty(String) Indicates whether the specified string is null or an Empty string.
IsNullOrWhiteSpace(String) Indicates whether a specified string is null, empty, or consists only of white-space characters.
Join(String, IEnumerable) Concatenates the members of a constructed IEnumerable collection of type String, using the specified separator between each member.
Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element.
Join(String, String[]) Concatenates all the elements of a string array, using the specified separator between each element.
Join(String, String[], Int32, Int32) Concatenates the specified elements of a string array, using the specified separator between each element.
Join(String, IEnumerable) Concatenates the members of a collection, using the specified separator between each member.
LastIndexOf(Char) Reports the zero-based index position of the last occurrence of a specified Unicode character within this
instance.
LastIndexOf(Char, Int32) Reports the zero-based index position of the last occurrence of a specified Unicode character within this
instance. The search starts at a specified character position and proceeds backward toward the beginning of the string.
LastIndexOf(Char, Int32, Int32) Reports the zero-based index position of the last occurrence of the specified Unicode character in a substring
within this instance. The search starts at a specified character position and proceeds backward toward the
beginning of the string for a specified number of character positions.
LastIndexOf(String) Reports the zero-based index position of the last occurrence of a specified string within this instance.
LastIndexOf(String, Int32) Reports the zero-based index position of the last occurrence of a specified string within this instance. The
search starts at a specified character position and proceeds backward toward the beginning of the string.
LastIndexOf(String, Int32, Int32) Reports the zero-based index position of the last occurrence of a specified string within this instance. The
search starts at a specified character position and proceeds backward toward the beginning of the string for a
specified number of character positions.
LastIndexOf(String, Int32, Int32, StringComparison)
Reports the zero-based index position of the last occurrence of a specified string within this instance. The
search starts at a specified character position and proceeds backward toward the beginning of the string for the specified number of character positions. A parameter specifies the type of comparison to perform when
searching for the specified string.
LastIndexOf(String, Int32, StringComparison)
Reports the zero-based index of the last occurrence of a specified string within the current Stringobject. The
search starts at a specified character position and proceeds backward toward the beginning of the string. A
parameter specifies the type of comparison to perform when searching for the specified string.
LastIndexOf(String, StringComparison) Reports the zero-based index of the last occurrence of a specified string within the current Stringobject. A
parameter specifies the type of search to use for the specified string.
LastIndexOfAny(Char[]) Reports the zero-based index position of the last occurrence in this instance of one or more characters
specified in a Unicode array.
LastIndexOfAny(Char[], Int32) Reports the zero-based index position of the last occurrence in this instance of one or more characters
specified in a Unicode array. The search starts at a specified character position and proceeds backward
toward the beginning of the string.
LastIndexOfAny(Char[], Int32, Int32) Reports the zero-based index position of the last occurrence in this instance of one or more characters
specified in a Unicode array. The search starts at a specified character position and proceeds backward
toward the beginning of the string for a specified number of character positions.
https://msdn.microsoft.com/en-us/library/system.string.isnullorempty(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.empty(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dd783876(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/9eekhta0(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dd988350(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/57a79xd0(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/tk0xe5h0(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/dd992421(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/0w96zd3d(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1tw91fa3(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131439(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1wdsy8fy(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/bc3z4t9d(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/d0z3tk9t(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224421(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224421(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224420(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224420(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms224422(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1d15dfa1(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/5kbkt4sh(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/81kkcfd4(v=vs.110).aspx
-
Normalize() Returns a new string whose textual value is the same as this string, but whose binary representation is in
Unicode normalization form C.
Normalize(NormalizationForm) Returns a new string whose textual value is the same as this string, but whose binary representation is in the
specified Unicode normalization form.
PadLeft(Int32) Returns a new string that right-aligns the characters in this instance by padding them with spaces on the left,
for a specified total length.
PadLeft(Int32, Char) Returns a new string that right-aligns the characters in this instance by padding them on the left with a
specified Unicode character, for a specified total length.
PadRight(Int32) Returns a new string that left-aligns the characters in this string by padding them with spaces on the right, for
a specified total length.
PadRight(Int32, Char) Returns a new string that left-aligns the characters in this string by padding them on the right with a specified
Unicode character, for a specified total length.
Remove(Int32) Returns a new string in which all the characters in the current instance, beginning at a specified position and
continuing through the last position, have been deleted.
Remove(Int32, Int32) Returns a new string in which a specified number of characters in the current instance beginning at a
specified position have been deleted.
Replace(Char, Char) Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced
with another specified Unicode character.
Replace(String, String) Returns a new string in which all occurrences of a specified string in the current instance are replaced with
another specified string.
Split(Char[]) Splits a string into substrings that are based on the characters in an array.
Split(Char[], Int32) Splits a string into a maximum number of substrings based on the characters in an array. You also specify the
maximum number of substrings to return.
Split(Char[], Int32, StringSplitOptions) Splits a string into a maximum number of substrings based on the characters in an array.
Split(Char[], StringSplitOptions) Splits a string into substrings based on the characters in an array. You can specify whether the substrings
include empty array elements.
Split(String[], Int32, StringSplitOptions) Splits a string into a maximum number of substrings based on the strings in an array. You can specify
whether the substrings include empty array elements.
Split(String[], StringSplitOptions) Splits a string into substrings based on the strings in an array. You can specify whether the substrings include
empty array elements.
StartsWith(String) Determines whether the beginning of this string instance matches the specified string.
StartsWith(String, Boolean, CultureInfo) Determines whether the beginning of this string instance matches the specified string when compared using
the specified culture.
StartsWith(String, StringComparison) Determines whether the beginning of this string instance matches the specified string when compared using
the specified comparison option.
Substring(Int32) Retrieves a substring from this instance. The substring starts at a specified character position and continues to
the end of the string.
Substring(Int32, Int32) Retrieves a substring from this instance. The substring starts at a specified character position and has a
specified length.
ToCharArray() Copies the characters in this instance to a Unicode character array.
https://msdn.microsoft.com/en-us/library/8eaxk1x2(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ebza6ck1(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/0zk6ydzx(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/92h5dc07(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/34d75d7s(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/36f2hz3a(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/9ad138yc(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/d8d7z2kk(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/czx8s9ts(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/b873y76a(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/c1bs0eda(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131450(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131448(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/1bwe3zdy(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/baketfxw(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/6k0axhx9(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ms131452(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ezftk57x(v=vs.110).aspx
-
ToCharArray(Int32, Int32) Copies the characters in a specified substring in this instance to a Unicode character array.
ToLower() Returns a copy of this string converted to lowercase.
ToLower(CultureInfo) Returns a copy of this string converted to lowercase, using the casing rules of the specified culture.
ToLowerInvariant() Returns a copy of this String object converted to lowercase using the casing rules of the invariant culture.
ToString() Returns this instance of String; no actual conversion is performed.(Overrides Object.ToString().)
ToString(IFormatProvider) Returns this instance of String; no actual conversion is performed.
ToUpper() Returns a copy of this string converted to uppercase.
ToUpper(CultureInfo) Returns a copy of this string converted to uppercase, using the casing rules of the specified culture.
ToUpperInvariant() Returns a copy of this String object converted to uppercase using the casing rules of the invariant culture.
Trim() Removes all leading and trailing white-space characters from the current String object.
Trim(Char[]) Removes all leading and trailing occurrences of a set of characters specified in an array from the
current String object.
TrimEnd(Char[]) Removes all trailing occurrences of a set of characters specified in an array from the current Stringobject.
TrimStart(Char[]) Removes all leading occurrences of a set of characters specified in an array from the current Stringobject.
Fields
Name Description
Empty Represents the empty string. This field is read-only.
Enumeracija Enum Temperatura { TempSmrzavanja=0, TempKljucanja=100 } Koriscenje: (Int) Temperatura.TempSmrzavanja transformacija tipova podataka
- Utvrdjivanje tipa: TypeOf( implicitna transformacija (npr. dodela byte vrednosti u integer ili integer u longautomatski je prihvaceno)
- Eksplicitna: type casting Int.Parse (). Ili (int)Promenljiva PROMENLJIVE
Deklaracija promenljive - Tip NazivPromenljive;
Inicijalizacija promenljive- NazivPromenljive = PocetnaVrednost;
Definicija promenljive = Deklaracija + Inicijalizacija KONSTANTA
https://msdn.microsoft.com/en-us/library/2c7h58e5(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/e78f86at(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/s8z5yt00(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.tolowerinvariant(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/8tc6ws5s(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.object.tostring(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/29dxe1x2(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/ewdd6aed(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/24kc78ka(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.toupperinvariant(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/t97s7bs3(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/d4tt83f9(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.trimend(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.trimstart(v=vs.110).aspxhttps://msdn.microsoft.com/en-us/library/system.string.empty(v=vs.110).aspx
-
Const int nazivkonstante=vrednost; OPERATORI I FUNKCIJE
= dodela vrednosti
== uporeivanje vrednosti ( ... ==null) C# provides many operators, which are symbols that specify which operations (math, indexing, function call, etc.) to perform in an expression. You
can overload many operators to change their meaning when applied to a user-defined type.
Operations on integral types (such as ==, !=, , &, |) are generally allowed on enumeration (enum) types.
The sections lists the C# operators starting with the highest precedence to the lowest. The operators within each section share the same precedence
level.
Primary Operators
These are the highest precedence operators. NOTE, you can click on the operators to go the detailed pages with examples.
x.y member access.
x?.y null conditional member access. Returns null if the left hand operand is null.
f(x) function invocation.
a[x] aggregate object indexing.
a?[x] null conditional indexing. Returns null if the left hand operand is null.
x++ postfix increment. Returns the value of x and then updates the storage location with the value of x that is one greater (typically adds the integer
1).
x-- postfix decrement. Returns the value of x and then updates the storage location with the value of x that is one less (typically subtracts the integer
1).
New type instantiation.
Typeof returns the System.Type object representing the operand.
Checked enables overflow checking for integer operations.
Unchecked disables overflow checking for integer operations. This is the default compiler behavior.
default(T) returns the default initialized value of type T, null for reference types, zero for numeric types, and zero/null filled in members for struct
types.
Delegate declares and returns a delegate instance.
Sizeof returns the size in bytes of the type operand.
-> pointer dereferencing combined with member access.
Unary Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
+x returns the value of x.
-x numeric negation.
!x logical negation.
~x bitwise complement.
++x prefix increment. Returns the value of x after updating the storage location with the value of x that is one greater (typically adds the integer 1).
--x prefix decrement. Returns the value of x after updating the storage location with the value of x that is one less (typically adds the integer 1).
(T)x type casting.
Await awaits a Task.
&x address of.
*x dereferencing.
Multiplicative Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x * y multiplication.
x / y division. If the operands are integers, the result is an integer truncated toward zero (for example, -7 / 2 is -3).
x % y modulus. If the operands are integers, this returns the remainder of dividing x by y. If q = x / y and r = x % y, then x = q * y + r.
Additive Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x + y addition.
x y subtraction.
Shift Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x > y shift bits right. If the left operand is int or long, then left bits are filled with the sign bit. If the left operand is uint or ulong, then left bits
are filled with zero.
Relational and Type-testing Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x < y less than (true if x is less than y).
x > y greater than (true if x is greater than y).
x = y greater than or equal to.
Is type compatibility. Returns true if the evaluated left operand can be cast to the type specified in the right operand (a static type).
https://msdn.microsoft.com/en-us/library/8edha89s.aspxhttps://msdn.microsoft.com/en-us/library/6zhxzbds.aspxhttps://msdn.microsoft.com/en-us/library/dn986595.aspxhttps://msdn.microsoft.com/en-us/library/0z4503sa.aspxhttps://msdn.microsoft.com/en-us/library/a3hd7ste.aspxhttps://msdn.microsoft.com/en-us/library/dn986595.aspxhttps://msdn.microsoft.com/en-us/library/36x43w8w.aspxhttps://msdn.microsoft.com/en-us/library/wc3z3k8c.aspxhttps://msdn.microsoft.com/en-us/library/fa0ab757.aspxhttps://msdn.microsoft.com/en-us/library/58918ffs.aspxhttps://msdn.microsoft.com/en-us/library/74b4xzyw.aspxhttps://msdn.microsoft.com/en-us/library/a569z7k8.aspxhttps://msdn.microsoft.com/en-us/library/xwth0h0d.aspxhttps://msdn.microsoft.com/en-us/library/0yw3tz5k.aspxhttps://msdn.microsoft.com/en-us/library/eahchzkf.aspxhttps://msdn.microsoft.com/en-us/library/s8bz4d5h.aspxhttps://msdn.microsoft.com/en-us/library/k1a63xkz.aspxhttps://msdn.microsoft.com/en-us/library/wch5w409.aspxhttps://msdn.microsoft.com/en-us/library/f2kd6eb2.aspxhttps://msdn.microsoft.com/en-us/library/d2bd4x66.aspxhttps://msdn.microsoft.com/en-us/library/36x43w8w.aspxhttps://msdn.microsoft.com/en-us/library/wc3z3k8c.aspxhttps://msdn.microsoft.com/en-us/library/0z4503sa.aspxhttps://msdn.microsoft.com/en-us/library/hh156528.aspxhttps://msdn.microsoft.com/en-us/library/sbf85k1c.aspxhttps://msdn.microsoft.com/en-us/library/z19tbbca.aspxhttps://msdn.microsoft.com/en-us/library/z19tbbca.aspxhttps://msdn.microsoft.com/en-us/library/3b1ff23f.aspxhttps://msdn.microsoft.com/en-us/library/0w4e0fzs.aspxhttps://msdn.microsoft.com/en-us/library/k1a63xkz.aspxhttps://msdn.microsoft.com/en-us/library/wch5w409.aspxhttps://msdn.microsoft.com/en-us/library/a1sway8w.aspxhttps://msdn.microsoft.com/en-us/library/xt18et0d.aspxhttps://msdn.microsoft.com/en-us/library/z5wecxwa.aspxhttps://msdn.microsoft.com/en-us/library/yxk8751b.aspxhttps://msdn.microsoft.com/en-us/library/hx063734.aspxhttps://msdn.microsoft.com/en-us/library/a59bsyk4.aspxhttps://msdn.microsoft.com/en-us/library/scekt9xw.aspx
-
As type conversion. Returns the left operand cast to the type specified by the right operand (a static type), but as returns null where (T)x would
throw an exception.
Equality Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x == y equality. By default, for reference types other than string, this returns reference equality (identity test). However, types can overload ==, so
if your intent is to test identity, it is best to use the ReferenceEquals method on object.
x != y not equal. See comment for ==. If a type overloads ==, then it must overload !=.
Logical AND Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x & y logical or bitwise AND. Use with integer types and enum types is generally allowed.
Logical XOR Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x ^ y logical or bitwise XOR. You can generally use this with integer types and enum types.
Logical OR Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x | y logical or bitwise OR. Use with integer types and enum types is generally allowed.
Conditional AND Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x && y logical AND. If the first operand is false, then C# does not evaluate the second operand.
Conditional OR Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x || y logical OR. If the first operand is true, then C# does not evaluate the second operand.
Null-coalescing Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
x ?? y returns x if it is non-null; otherwise, returns y.
Conditional Operator
This operator has higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operator to go
the details page with examples.
t ? x : y if test t is true, then evaluate and return x; otherwise, evaluate and return y.
Assignment and Lambda Operators
These operators have higher precedence than the next section and lower precedence than the previous section. NOTE, you can click on the operators
to go the detailed pages with examples.
x = y assignment.
x += y increment. Add the value of y to the value of x, store the result in x, and return the new value. If x designates an event, then y must be an
appropriate function that C# adds as an event handler.
x -= y decrement. Subtract the value of y from the value of x, store the result in x, and return the new value. If x designates an event, then y must
be an appropriate function that C# removes as an event handler
x *= y multiplication assignment. Multiply the value of y to the value of x, store the result in x, and return the new value.
x /= y division assignment. Divide the value of x by the value of y, store the result in x, and return the new value.
x %= y modulus assignment. Divide the value of x by the value of y, store the remainder in x, and return the new value.
x &= y AND assignment. AND the value of y with the value of x, store the result in x, and return the new value.
x |= y OR assignment. OR the value of y with the value of x, store the result in x, and return the new value.
x ^= y XOR assignment. XOR the value of y with the value of x, store the result in x, and return the new value.
x = y right-shift assignment. Shift the value of x right by y places, store the result in x, and return the new value.
=> lambda declaration.
PROGRAMSKE STRUKTURE SEKVENCA naredba; {blok naredbi} SELEKCIJA
- if (uslov) {} else {} - switch (izraz) { Case konstanta: Naredba; Naredbaskoka; NPR BREAK;
https://msdn.microsoft.com/en-us/library/cscsdfbt.aspxhttps://msdn.microsoft.com/en-us/library/53k8ybth.aspxhttps://msdn.microsoft.com/en-us/library/3tz250sf.aspxhttps://msdn.microsoft.com/en-us/library/sbf85k1c.aspxhttps://msdn.microsoft.com/en-us/library/zkacc7k1.aspxhttps://msdn.microsoft.com/en-us/library/kxszd0kx.aspxhttps://msdn.microsoft.com/en-us/library/2a723cdk.aspxhttps://msdn.microsoft.com/en-us/library/6373h346.aspxhttps://msdn.microsoft.com/en-us/library/ms173224.aspxhttps://msdn.microsoft.com/en-us/library/ty67wk28.aspxhttps://msdn.microsoft.com/en-us/library/sbkb459w.aspxhttps://msdn.microsoft.com/en-us/library/sa7629ew.aspxhttps://msdn.microsoft.com/en-us/library/2y9zhhx1.aspxhttps://msdn.microsoft.com/en-us/library/s2bkaksf.aspxhttps://msdn.microsoft.com/en-us/library/d31sybc9.aspxhttps://msdn.microsoft.com/en-us/library/ydwa9zh0.aspxhttps://msdn.microsoft.com/en-us/library/e669ax02.aspxhttps://msdn.microsoft.com/en-us/library/h5f1zzaw.aspxhttps://msdn.microsoft.com/en-us/library/0zbsw2z6.aspxhttps://msdn.microsoft.com/en-us/library/ayt2kcfb.aspxhttps://msdn.microsoft.com/en-us/library/23as4533.aspxhttps://msdn.microsoft.com/en-us/library/bb311046.aspx
-
Default : AKO NIJE NIJEDAN OD IZBORA }
ITERACIJA
while, While (uslov) { }
- do while Do { } while (i
-
3. OBLAST OBJEKTNO-ORJENTISANO PROGRAMIRANJE u C# Teorija Klasa je osnovni gradivni element objektno-orjentisanog programa. Opisuje se svojstvima (atributima) i ponaanjem (metodama). Objekat je konkretna pojava neke klase. Objekat se moe smatrati promenljivom iji je tip klasa. Da bi se kreirao objekat u memoriji, potrebno je da se prvo deklarie da je odreenog tipa (da pripada klasi, tj. Da je objekat te klase), a zatim instancira (pozivom konstruktora klase) pripremi prostor u memoriji za smetaj njegovih atributa, ime se istovremeno i inicijalizuju svi atributi na poetnu vrednost. Stanje objekta opisano je vrednostima njegovih atributa u svakom trenutku. Objekat moe da menja stanje. Preporuljivo je da se objektu menja stanje na osnovu poziva odgovarajuih metoda, a ne direktnim pristupom atributima.
OOP u C# Standardne biblioteke klasa Using NazivBibliotekeKlasa;
Klasa:
Class NazivKlase { }
Konstruktor klase: Class NazivKlase { // konstruktor
public NazivKlase () { } }
Polje klase: Class NazivKlase { // privatni atribut, tj. polje private string m_prezime; // konstruktor public NazivKlase () { } }
Svojstvo klase (javni atribut) readonly ima samo get, writeonly ima samo set:
Class NazivKlase { // privatni atribut, tj. polje private string m_prezime; // javni atribut, tj. svojstvo public string Prezime { get { return m_prezime;
} set { m_prezime=value; }
-
} // konstruktor public NazivKlase () { } }
Proirenje konstruktora inicijalizacijom promenljivih, tj. Privatnih atributa
Class NazivKlase { // privatni atribut, tj. polje private string m_prezime; // javni atribut, tj. svojstvo public string Prezime { get { return m_prezime;
} Set { m_prezime=value; }
} // konstruktor public NazivKlase () { } m_prezime=; }
Kreiranje objekta: NazivKlase objNovaKlasa = new NazivKlase (); - deklaracija + instanciranje (poziv konstruktora ukljucuje i inicijalizaciju promenljivih, tj. privatnih atributa, polja). Unitavanje objekta objNovaKlasa.Dispose(); Destruktor ne poziva se eksplicitno u kodu ~NovaKlasa(){ //naredbe } Korienje objekta postavljanje vrednosti atributu: objNovaKlasa.Prezime = Markovic; OVDE SE POZIVA U SUSTINI METODA SET Dodavanje metode modifikatori pristupa: private, public, protected, internal
Class NazivKlase { // privatni atribut, tj. polje Private string m_prezime; Private string m_ime; // javni atribut, tj. svojstvo Public string Prezime {
-
get { return m_prezime;
} Set { m_prezime=value; }
} Public string Ime { get { return m_ime;
} Set { m_ime=value; }
} // konstruktor public NazivKlase () { } m_prezime=; m_ime=; }
public string DajPrezimeIme() { return this.m_prezime + + this.m_ime; } KLJUNA RE THIS ukazuje na trenutni objekat sa kojim se radi Korienje klase poziv metode String PrezimeIme = objNovaKlasa.DajPrezimeIme(); Konstruktor sa parametrima
// konstruktor public NazivKlase (string pocetnoPrezime, string pocetnoIme) { } m_prezime=pocetnoPrezime; m_ime=pocetnoIme; }
Parametri metode Prosledjivanje po reference ili po vrednosti (ulazni, izlazni) ref int Prom, in int prom, out int prom Poziv: ref Prom, out prom, in prom Preoptereene(preklapajue OVERLOADING) metode metode u okviru iste klase koje imaju isti naziv, a razliite parametre public string DajPrezimeIme() { return this.m_prezime + + this.m_ime; }
-
public string DajPrezimeIme(bool prvoPrezime) { return this.m_prezime + + this.m_ime; } Nasleivanje Public class DrugaKlasa: PrvaKlasa { } Poziv konstruktora osnovne klase: Public DrugaKlasa (): base () { } Zatita osnovne klase protected modifikator pristupa za atribute i metode Nadjaavanje (OVERRIDE) svojstava i metoda u izvedenoj klasi U osnovnoj klasi: Virtual public string ID... U izvedenoj klasi: Override public string ID Specifine varijante sealed (zapeaena) class ( ne moe da se nasledi), new public void Metod (naglaava se da nije nadjaana metoda, ne ponaa se polimorfno), abstract (klasa, metoda, atribut) mora biti nasleena, nema objekte Polimorfizam objektu osnovne klase dodeliti referencu na izvedenu klasu i tada treba da bude primenjena metoda izvedene klase. Moe se videti kod kolecija (niz, liste) kada se napravi niz elemenata osnovne klase, a dodele kao reference elementi izvedenih klasa. Svaka treba da prilikom poziva istih naziva metoda da dobije svoj rezultat, kao rezultat nadjacavanja metoda. Statike klase imaju statike atribute i metode. Ne instanciraju se, koriste se direktno putem naziva klase. Public static int Broj =5;
STRUKTURE SA OBJEKTIMA KLASA
NIZ, UREENA LISTA (LIST, ARRAY LIST) NazivKlase [] nizklasa = {new NazivKlase(), new NazivKlase() }; List ArrayList Indekser
INTERFEJSI usluge jedne ili vie klasa, sakriva implementaciju, ugovor da ce klasa koja implementira interfejs da se ponasa na odredjeni nacin Public Interface imeinterfejsa { } Svojstvo: Int Imesvojstva { Get; Set; }
-
Metod Void NazivMetode (parameter); Klasa koja implementira interfejs Public class KlasaInterfejsa: NazivInterfejsa { }
NAPREDNI NIVO UPRAVLJANJE DOGAAJIMA (EVENTS, ADD HANDLER, SYSTEM.EVENTARGS, DELEGATI)
META PODACI O KLASAMA
DINAMIKO POVEZIVANJE DLL, PROGRAMSKI SKLOP (ASSEMBLY MANIFEST)
GARBAGE COLLECTION UPRAVLJANJE MEMORIJOM
SERIJALIZACIJA SNIMANJE KLASA U FAJLOVIMA ----------------------------------------------------------------- --------------------------------------------------------------------------- KONVENCIJE NAZIVANJA:
Casing: camelCasing privatni atributi, parametri metoda, promeljive unutar metoda, PascalCasing sve ostalo
Privatni atributi- prefix m_, Property bez prefiksa RAD SA STRUKTURAMA
NIZ An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Declaring Arrays To declare an array in C#, you can use the following syntax: datatype[] arrayName;
where,
datatype is used to specify the type of elements in the array.
[ ] specifies the rank of the array. The rank specifies the size of the array.
arrayName specifies the name of the array. For example, double[] balance;
Initializing an Array Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array. For example, double[] balance = new double[10];
Assigning Values to an Array You can assign values to individual array elements, by using the index number, like: double[] balance = new double[10]; balance[0] = 4500.0;
You can assign values to the array at the time of declaration, as shown: double[] balance = { 2340.0, 4523.69, 3421.0};
You can also create and initialize an array, as shown: int [] marks = new int[5] { 99, 98, 92, 97, 95};
You may also omit the size of the array, as shown: int [] marks = new int[] { 99, 98, 92, 97, 95};
You can copy an array variable into another target array variable. In such case, both the target and source point to the same memory location: int [] marks = new int[] { 99, 98, 92, 97, 95}; int[] score = marks;
-
When you create an array, C# compiler implicitly initializes each array element to a default value depending on the array type. For example, for an int array all elements are initialized to 0. Accessing Array Elements An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example, double salary = balance[9];
The following example, demonstrates the above-mentioned concepts declaration, assignment, and accessing arrays: using System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { int [] n = new int[10]; /* n is an array of 10 integers */ int i,j; /* initialize elements of array n */ for ( i = 0; i < 10; i++ ) { n[ i ] = i + 100; } /* output each array element's value */ for (j = 0; j < 10; j++ ) { Console.WriteLine("Element[{0}] = {1}", j, n[j]); } Console.ReadKey(); } } }
When the above code is compiled and executed, it produces the following result: Element[0] = 100 Element[1] = 101 Element[2] = 102 Element[3] = 103 Element[4] = 104 Element[5] = 105 Element[6] = 106 Element[7] = 107 Element[8] = 108 Element[9] = 109
Using the foreach Loop In the previous example, we used a for loop for accessing each array element. You can also use a foreach statement to iterate through an array. using System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { int [] n = new int[10]; /* n is an array of 10 integers */ /* initialize elements of array n */ for ( int i = 0; i < 10; i++ ) { n[i] = i + 100; } /* output each array element's value */ foreach (int j in n ) { int i = j-100; Console.WriteLine("Element[{0}] = {1}", i, j); } Console.ReadKey(); } } }
ARRAY LIST
-
It represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array.
However, unlike array you can add and remove items from a list at a specified position using an index and the array resizes itself
automatically. It also allows dynamic memory allocation, adding, searching and sorting items in the list.
Methods and Properties of ArrayList Class
The following table lists some of the commonly used properties of the ArrayList class:
Property Description
Capacity Gets or sets the number of elements that the ArrayList can contain.
Count Gets the number of elements actually contained in the ArrayList.
IsFixedSize Gets a value indicating whether the ArrayList has a fixed size.
IsReadOnly Gets a value indicating whether the ArrayList is read-only.
Item Gets or sets the element at the specified index.
The following table lists some of the commonly used methods of the ArrayList class:
Sr.No. Methods
1 public virtual int Add(object value);
Adds an object to the end of the ArrayList.
2 public virtual void AddRange(ICollection c);
Adds the elements of an ICollection to the end of the ArrayList.
3 public virtual void Clear();
Removes all elements from the ArrayList.
4 public virtual bool Contains(object item);
Determines whether an element is in the ArrayList.
5 public virtual ArrayList GetRange(int index, int count);
-
Returns an ArrayList which represents a subset of the elements in the source ArrayList.
6 public virtual int IndexOf(object);
Returns the zero-based index of the first occurrence of a value in the ArrayList or in a portion
of it.
7 public virtual void Insert(int index, object value);
Inserts an element into the ArrayList at the specified index.
8 public virtual void InsertRange(int index, ICollection c);
Inserts the elements of a collection into the ArrayList at the specified index.
9 public virtual void Remove(object obj);
Removes the first occurrence of a specific object from the ArrayList.
10 public virtual void RemoveAt(int index);
Removes the element at the specified index of the ArrayList.
11 public virtual void RemoveRange(int index, int count);
Removes a range of elements from the ArrayList.
12 public virtual void Reverse();
Reverses the order of the elements in the ArrayList.
13 public virtual void SetRange(int index, ICollection c);
Copies the elements of a collection over a range of elements in the ArrayList.
14 public virtual void Sort();
Sorts the elements in the ArrayList.
15 public virtual void TrimToSize();
Sets the capacity to the actual number of elements in the ArrayList.
Example
The following example demonstrates the concept:
-
using System;
using System.Collections;
namespace CollectionApplication
{
class Program
{
static void Main(string[] args)
{
ArrayList al = new ArrayList();
Console.WriteLine("Adding some numbers:");
al.Add(45);
al.Add(78);
al.Add(33);
al.Add(56);
al.Add(12);
al.Add(23);
al.Add(9);
Console.WriteLine("Capacity: {0} ", al.Capacity);
Console.WriteLine("Count: {0}", al.Count);
Console.Write("Content: ");
foreach (int i in al)
{
Console.Write(i + " ");
}
Console.WriteLine();
Console.Write("Sorted Content: ");
al.Sort();
foreach (int i in al)
{
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
-
}
}
}
When the above code is compiled and executed, it produces the following result:
Adding some numbers: Capacity: 8 Count: 7 Content: 45 78 33 56 12 23 9 Content: 9 12 23 33 45 56 78
TIPIZIRANA LISTA You have already learned about ArrayList in the previous section. An ArrayList resizes automatically as it grows. The List collection is the same as an ArrayList except that List is a generic collection whereas ArrayList is a non-generic collection.
List can be initialized in the following two ways.
Example: List Initialization
List intList = new List(); //Or IList intList = new List();
In the above example, the first statement uses List type variable, whereas the second statement uses IList type variable to initialize List. List is a concreate implementation of IList interface. In the object-oriented programming, it is advisable to program to interface rather than concreate class. So use IList type variable to create an object of List.
List includes more helper methods than IList interface. The table shown below lists important properties and methods of List, which are initialized using a List:
Property Usage
Items Gets or sets the element at the specified index
Count Returns the total number of elements exists in the List
Method Usage
Add Adds an element at the end of a List.
AddRange Adds elements of the specified collection at the end of a List.
BinarySearch Search the element and returns an index of the element.
Clear Removes all the elements from a List.
Contains Checks whether the speciied element exists or not in a List.
http://msdn.microsoft.com/en-us/library/5y536ey6(v=vs.110).aspx
-
Property Usage
Find Finds the first element based on the specified predicate function.
Foreach Iterates through a List.
Insert Inserts an element at the specified index in a List.
InsertRange Inserts elements of another collection at the specified index.
Remove Removes the first occurence of the specified element.
RemoveAt Removes the element at the specified index.
RemoveRange Removes all the elements that match with the supplied predicate function.
Sort Sorts all the elements.
TrimExcess Sets the capacity to the actual number of elements.
TrueForAll Determines whether every element in the List matches the conditions defined by the specified predicate.
Add Elements into List:
Use the Add() method to add an element into a List collection. The following example adds int value into a List of int type.
Add() signature: void Add(T item)
Example: Adding elements into List
IList intList = new List(); intList.Add(10); intList.Add(20); intList.Add(30); intList.Add(40); IList strList = new List(); strList.Add("one"); strList.Add("two"); strList.Add("three"); strList.Add("four"); strList.Add("four"); strList.Add(null); strList.Add(null); IList studentList = new List(); studentList.Add(new Student()); studentList.Add(new Student()); studentList.Add(new Student());
Try it
You can also add elements at the time of initialization using object initializer syntax as below:
http://www.tutorialsteacher.com/codeeditor?cid=cs-v8Gtvl
-
Example: Add elements using object initializer syntax
IList intList = new List(){ 10, 20, 30, 40 }; //Or IList studentList = new List() { new Student(){ StudentID=1, StudentName="Bill"}, new Student(){ StudentID=2, StudentName="Steve"}, new Student(){ StudentID=3, StudentName="Ram"}, new Student(){ StudentID=1, StudentName="Moin"} };
Try it
AddRange:
The AddRange() method adds all the elements from another collection.
AddRange() signature: void AddRange(IEnumerable collection)
Example: AddRange
IList intList1 = new List(); intList1.Add(10); intList1.Add(20); intList1.Add(30); intList1.Add(40); List intList2 = new List(); intList2.AddRange(intList1);
Try it
Note :The AddRange() method will only be applicable if you initialized with a List variable. IList doesn't include the
AddRange() method.
Access List collection:
Use a foreach or for loop to iterate a List collection.
Example: Accessing List
List intList = new List() { 10, 20, 30 }; intList.ForEach(el => Console.WriteLine(el));
Try it
If you have initialized the List with an IList interface then use seperate foreach statement with implicitly typed variable:
Example: Accessing List
IList intList = new List() { 10, 20, 30, 40 }; foreach (var el in intList) Console.WriteLine(el);
Try it
http://www.tutorialsteacher.com/codeeditor?cid=cs-rPe9Kphttp://www.tutorialsteacher.com/codeeditor?cid=cs-0UAMpihttp://www.tutorialsteacher.com/codeeditor?cid=cs-At1qDbhttp://www.tutorialsteacher.com/codeeditor?cid=cs-At1qDb
-
Output:
10
20
30
40
Access individual items by using an indexer (i.e., passing an index in square brackets):
Example: Accessing List
IList intList = new List() { 10, 20, 30, 40 }; int elem = intList[1]; // returns 20
Use the Count property to get the total number of elements in the List.
Example: Access List elements
IList intList = new List() { 10, 20, 30, 40 }; Console.Write("Total elements: {0}", intList.Count); Output:
Total elements: 4
Use for loop to access list as shown below:
Example: Accessing List using for loop example:
IList intList = new List() { 10, 20, 30, 40 }; for (int i = 0; i < intList.Count; i++) Console.WriteLine(intList[i]);
Try it
Output:
10
20
http://www.tutorialsteacher.com/codeeditor?cid=cs-At1qDb
-
30
40
List implements IList, so List implicitly type cast to IList.
Example: Access List
static void Print(IList list) { Console.WriteLine("Count: {0}", list.Count); foreach (string value in list) { Console.WriteLine(value); } } static void Main(string[] args) { string[] strArray = new string[2]; strArray[0] = "Hello"; strArray[1] = "World"; Print(strArray); List strList = new List(); strList.Add("Hello"); strList.Add("World"); Print(strList); }
Try it
Output:
Hello
World
Hello
World
Insert into List:
The Insert() method inserts an element into a List collection at the specified index.
Insert() signature:void Insert(int index, T item);
Example: Insert elements into List
IList intList = new List(){ 10, 20, 30, 40 }; intList.Insert(1, 11);// inserts 11 at 1st index: after 10. foreach (var el in intList)
http://www.tutorialsteacher.com/codeeditor?cid=cs-2nSZAO
-
Console.Write(el);
Try it
Output:
10
11
20
30
40
Remove Elements from List:
The Remove() and RemoveAt() methods remove items from a List collection.
Remove() signature: bool Remove(T item)
RemoveAt() signature: void RemoveAt(int index)
Example: Remove elements from List
IList intList = new List(){ 10, 20, 30, 40 }; intList.Remove(10); // removes the 10 from a list intList.RemoveAt(2); //removes the 3rd element (index starts from 0) foreach (var el in intList) Console.Write(el);
OBRADA GRESAKA
An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional
circumstance that arises while a program is running, such as an attempt to divide by zero.
Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four
keywords: try, catch, finally, and throw.
try: A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch
blocks.
catch: A program catches an exception with an exception handler at the place in a program where you want to handle
the problem. The catch keyword indicates the catching of an exception.
http://www.tutorialsteacher.com/codeeditor?cid=cs-8ygFOR
-
finally: The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For
example, if you open a file, it must be closed whether an exception is raised or not.
throw: A program throws an exception when a problem shows up. This is done using a throw keyword.
Syntax
Assuming a block raises an exception, a method catches an exception using a combination of the try and catch keywords. A
try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as
protected code, and the syntax for using try/catch looks like the following:
try
{
// statements causing exception
}
catch( ExceptionName e1 )
{
// error handling code
}
catch( ExceptionName e2 )
{
// error handling code
}
catch( ExceptionName eN )
{
// error handling code
}
finally
{
// statements to be executed
}
You can list down multiple catch statements to catch different type of exceptions in case your try block raises more than one
exception in different situations.
Exception Classes in C#
C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from
the System.Exception class.