C# Notes
C# Notes
Mrs.P.KAVITHAPANDIAN
ASP/CSE
UNIT- I
C# LANGUAGE BASICS
.Net Architecture - Core C# - Variables -
Data Types - Flow control - Objects and
Types- Classes and Structs - Inheritance-
Generics – Arrays and Tuples - Operators
and Casts – Indexers
www.rejinpaul.com
Introduction to .NET
• Content :
– Introduction to .NET Technology
Introduction to .NET Technology
What is .NET ?
Microsoft.NET is a Framework
– Microsoft .NET is a Framework which provides a common
platform to Execute or, Run the applications developed in
various programming languages.
• CLR ensures:
– A common runtime environment for all .NET languages
– Uses Common Type System (strict-type & code-verification)
– Memory allocation and garbage collection
– Intermediate Language (IL) to native code compiler.
Which Compiles MSIL code into native executable code
– Security and interoperability of the code with
other languages
• Over 36 languages supported today
– C#, VB, Jscript, Visual C++ from Microsoft
– Perl, Python, Smalltalk, Cobol, Haskell, Mercury, Eiffel, Oberon, Oz, Pascal, APL,
CAML, Scheme, etc.
Execution in CLR
Compiler Compiler
Compiler
Managed code Assembly IL Code
• Simple
• Modern
• Object-Oriented
• Type-safe
• Versionable
• Compatible
• Secure
Core c#
include:
using System;
namespace Wrox
{
Program
2. Reference types
• Variables of value types directly contain their data
whereas variables of reference types store
references to their data, the latter being known as
objects. With reference types, it's possible for two
variables to reference the same object and thus
possible for operations on one variable to affect the
object referenced by the other variable. With value
types, the variables each have their own copy of the
data, and it isn't possible for operations on one to
affect the other (except for ref and out parameter
variables).
• Types and variables.docx
Flow Control
statement(s)
• If more than one statement is to be executed
as part of either condition, these statements
need to be joined together into a block using
curly braces ({.}). (This also applies to other C#
constructs where statements can be joined
into a block, such as the for and while loops):
bool
isZero; if (i
== 0)
{
isZero = true;
Console.WriteLine("i is
Zero");
}
else
{
isZero = false; C
onsole.WriteLine("i is
Non-zero");
}
using System;
namespace Wrox
{
class MainEntryPoint {
static void Main(string[] args)
{
Console.WriteLine("Type in a string");
string input; input = Console.ReadLine();
if (input == "")
{
switch (integerA)
{
case 1: Console.WriteLine("integerA
=1"); break;
case 2: Console.WriteLine("integerA
=2"); break;
case 3: Console.WriteLine("integerA
=3"); break;
default:
Do
{
// This loop will at least execute once, even if
Condition is false.
MustBeCalledAtLeastOnce(); condition =
CheckCondition();
}
while (condition);
The foreach Loop
{
public static bool AreEqual(int value1, int
value2)
{
return value1 == value2;
}
}
}
• The above code implementation is very straight forward.
Here we created two classes with the
name ClsCalculator and ClsMain. Within
• If both are equal then it returns true else it will return false.
• The above AreEqual() method works as expected as it is
and more importantly it will only work with the integer
values as this is our initial requirement.
• Suppose our requirement changes, now we also need
to check whether two string values are equal or not.
• Here in the above example, in order to make
following:
• Interface
• Abstract class
• Class
• Method
• Static method
• Property
• Event
• Delegates
• Operator
Advantages of Generics in C#
https://dotnettutorials.net/lesson/generics-
csharp/
what is boxing and unboxing in c#
C#
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Misc Operators
• Operators are used to perform operations on
variables and values.Example int x = 100 + 50;
www.rejinpaul.com
www.rejinpaul.com
Operator Precedence in C#
Introduction to C#
C# is a general-purpose, modern and object-oriented programming
language pronounced as “See sharp”. It was developed by Microsoft led
by Anders Hejlsberg and his team within the .Net initiative and was
approved by the European Computer Manufacturers Association (ECMA)
and International Standards Organization (ISO).
Why C#?
C# has many other reasons for being popular and in demand. Few of
the reasons are mentioned below:
1. Easy to start: C# is a high-level language so it is closer to other
popular programming languages like C, C++, and Java and thus
becomes easy to learn for anyone.
There are various online IDEs such as GeeksforGeeks ide, CodeChef ide
etc. which can be used to run C# programs without installing.
Programming in C#:
Since the C# is a lot similar to other widely used languages syntactically,
it is easier to code and learn in C#.
Programs can be written in C# in any of the widely used text editors like
Notepad++, gedit, etc. or on any of the compilers. After writing the
program save the file with the extension .cs
Console.ReadKey();
}
}
}
Explanation:
1. Comments: Comments are used for explaining code and are used
in similar manner as in Java or C or C++. Compilers ignore the comment
entries and does not execute them. Comments can be of single line or
multiple lines.
Single line Comments:
Syntax:
// Single line comment
Applications:
● C# is widely used for developing desktop applications, web
applications and web services.
● It is used in creating applications of Microsoft at a large scale.
● C# is also used in game development in Unity (game engine).
C# ADVANCED FEATURES
Delegates - Lambdas - Lambda Expressions -
Events - Event Publisher - Event
Listener - Strings and Regular Expressions -
Generics - Collections - Memory
Management and Pointers - Errors and
Exceptions - Reflection
Delegates
www.rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
www.rejinpaul.com
Lambdas
Lambda Expressions
Events
Event Publisher
www.rejinpaul.com
Event Listener
Memory
Management and Pointers
www.rejinpaul.com
• The following figure shows the managed heap
after a collection.
• The following code demonstrates how
resources are allocated and managed:
• class Application
kinds
MethodInfo Describes the class method and gives access to its metadata
ParameterInfo Describes the parameters of a method and gives access to its metadata
EventInfo Describes the event info and gives accessto its metadata
PropertyInfo Discovers the attributes of a property and provides access to property metadata
Obtains information about the attributes of a member and provides access to
MemberInfo
member metadata
• Note: There are numerous other classes, the
namespace Reflection_Demo {
class Program {
// Main Method
Name : String
Full Name : System.String
Namespace : System
Base Type : System.Object
UNIT III
3
Diagnostics.
• [System.Diagnostics.DebuggerDisplay("{ID} - {Mod
el}- {Manufacturer} - {ProductionDate}")]
• public class Car
• {
• public int ID { get; set; }
• public string Model { get; set; }
• public string Manufacturer { get; set; }
• public DateTime ProductionDate { get; set; }
• }
Tasks, Threads and Synchronization
Why need Tasks
Eg: Thread.Sleep(300)
Join
Thread2 Executed.
Thread1 Executed.
After Thread1
After Thread2
www.rejinpaul.com
Output:
Total: 50028434
Count: 1000000
Locking
• Lock
• Mutex
Lock
Mutex
Mutex stands for Mutual Exclusion. The Mutex type
ensures blocks of code are executed only once at a
time. It is basically used in a situation where
resources has to be shared by multiple threads
simultaneously.
.Net Security
.NET applications
• To understand how resources are stored, let us peek into the XML
file. In our case, let us look at our first resource of HelloWorld.
The Generated Access
Class
• Resx files also generate access classes so that
we can more naturally access our resources.
• In our case, we have a Language class created
using the filename of our parent resx file.
• The sub topics:
• 1. Resource manager
• 2.Culture
• 3. ResourceProperties
ResourceManawgwewr.rejinpaul.c
om
• The Culture property allows us to set the CultureInfo of our Language class.
• As we’ll see later in the post, we can affect what resources we access
by changing this property.
Resource
w w w. rejinpaul.com
Proper t ie s
• The resource generator will be helpful and
generate named properties for each of our resource
values.
• In this post, we can see a created string property
for HelloWorld and Woot.
Putting Our Resx
w w w .re ji npaul.com
Fi l e s T o
Work
Conclusion:
3. It is platform independent.
4. Its self-documenting format describes the structure and
field names as well as specific values.
5. XML is heavily used to store the data and share the data.
entire XML is parsed and a DOM tree (of the nodes in the XML) is
generated and returned.
• DOM Stands for Document Object Model and it
represent an XML Document into tree format which each
element
representing tree branches. dom package while DOM Parser for
Java is in JAXP (Java API for XML Parsing) package. SAX XML Parser
in Java. SAX Stands for Simple API for XML Parsing.
Let's understand the working of XML
• SAX provides a mechanism for reading data from an XML document that is
an alternative to that provided by the Document Object Model (DOM).
<DocumentElement param="value">
• </FirstElement>
• <?some_pi some_attr="some_value"?>
• <SecondElement param2="something"> Pre-Text
• <Inline>Inlined text</Inline> Post-text.
</SecondElement>
• </DocumentElement>
generate a sequence of events like the following :
• XML Text node, with data equal to "¶ Some Text" (note: certain white spaces
can be changed)
• XML Element end, named FirstElement
Introduction
XML provides platform independent, self-descriptive and very flexible
way to represent your data. .NET has harnessed the capabilities of XML
in variety of ways. In addition to providing W3C compatible classes
.NET also provides additional classes which make XML document
manipulation easy.
XML Parsers
To access the content of an XML document you need to parse the
document and reach to the specific parts of it. The software which
allows you to do that is called as XML parser.
The parsers are of two types:
■ DOM parsers : These parsers built a tree of XML document in
memory and allow navigation to various nodes and attributes.
■ SAX parsers : These parsers process XML document in sequential
fashion. They have low memory footprint than DOM parsers.
In MSXML Ver.3, (Microsoft XML Core Services (MSXML) are set of
services that allow applications written in JScript, VBScript, and
Microsoft development tools to build Windows-native XML-based
applications). Microsoft has provided both of the parsers for our use.
In .NET we have DOM parser matching closely with existing MSXML
parser. The SAX parser has undergone some variation but provides
similar functionality.
The pre-.NET parser i.e. MSXML provided classes and interfaces closely
matching W3C recommendations. .NET also follows the same tradition
but adds many easy to use and flexible ways to manipulate XML
documents.
XML and .NET
XML related classes are available in System.XML namespace. In this article we will primarily discuss
about .NET specific classes for reading and writing XML documents.
To read XML documents System.XML provides a class called XmlTextReader. This class is derived from
XmlReader and provides easy access to various parts of XML document. This class can be thought as
forward-only and read only cursor.
To write XML documents System.XML provides a class called XmlTextWriter. This class is derived from
XmlWriter and allows quick writing of XML documents.
The methods provided by these classes are very easy to use and self explaining as compared to W3C
DOM . This is mainly because these classes allow various methods to be called directly on themselves.
They provide 'current node' for you to manipulate as opposed to W3C DOM classes where you have to
track individual nodes. These classes do not require some thing like
mydoc.ChildNodes(0).ChildNodes(1). to access various attributes or content of the node.
Using XmlTextReader Class
■ First import the System.XML namespace. If you are using Visual Studio.NET then Add
Reference to System.Xml.dll
e.g. In VB.NET
Imports System.Xml
■ Create instance of XmlTextReader class and load the XML document.
e.g. In VB.NET
e.g. In VB.NET
do while (reader.Read())
'do some action here
loop
The Read() method returns true if the node is successfully read else returns false. If node is successfully
read, you can use properties and methods on the node to perform tasks like checking node type, access
attributes, access content of node etc. You can call these methods directly on reader object.
Let's prepare the necessary variables for the user properties. We can't assign values
directly to the instance since its properties are read-only. Another option would be to
allow for it to be modified externally, but if we did we'd lose a part of the encapsulation.
We'll initialize the properties with default values which will remain there in case the
value isn't written in the XML file. The current element's name needs to be stored
somewhere, so we'll declare a string variable element for it. We'll write the code in a
using block.
string name =
""; int age = 0;
DateTime registered = DateTime.Now;
string element = "";
Let's start by parsing the file. The XmlReader class reads a file line by line, from top to
bottom. We call the Read() method on its instance. It returns the next Node each time it
calls it. A node can be an element, an attribute, or an element's text value (we'll mainly
focus on Element, Text, and EndElement), another node type could be a comment,
which isn't very important for us at the moment. Once the reader reaches the end of the
file, the Read() method returns false, otherwise, it returns true. We'll load the document
nodes gradually using a while loop:
while (xr.Read())
There are several useful properties on the XmlReader instance. We'll be using NodeType
which is where the type of the current node, on which the reader is located at, is stored.
Next, we'll use the Name and Value property in which the name of the current node and
its value is stored (if it has any).
We'll mainly focus on two types of nodes: Element and Text. Let's react to them. We'll
add in empty condition bodies for now:
if (xr.NodeType == XmlNodeType.Element)
}
Every time we encounter a user element, we load the age attribute using the
getAttribute() method whose parameter is the attribute's name. The current element's
attribute can be read easily. However, it's not that simple with reading its value.
Although there are methods like ReadContentAs-Type(), beware, they implicitly call the
Read() method for some reason which messes with the while loop. Reading values like
this would work properly in non-nested XML files. I tried to find a workaround for this
but the solutions were so awkward that I ended up not using the ReadContentAs...()
methods at all. Here's what the first condition looks like:
if (element == "user")
age = int.Parse(xr.GetAttribute("age"));
}
Let's move on to the next branch, i.e. processing the element's values. We'll use the
element variable and add it to a switch. We'll assign the value to the corresponding
property according to the value in element:
switch (element)
case "name":
name = xr.Value;
break;
case "registered":
registered = DateTime.Parse(xr.Value);
break;
}
We're already very close to finishing. The brighter ones among you surely noticed that
we won't be adding users anywhere. We'll do so after we reach the closing user
element. Now, let's add one last condition:
Document object model (DOM) is a platform and language neutral interface that allows
programs and scripts to dynamically access and update XML and HTML documents. The
DOM API is a set of language independent, implementation neutral interfaces and
objects based on the Object Management Group (OMG) Interface Definition Language
(IDL) specification (not the COM) version of IDL).
DOM defines the logical structure of a document's data. You can access the document in
a structured format (generally through a tree format). Tree nodes and entities represent
the document's data. DOM also helps developers build XML and HTML documents, as
well as to add, modify, delete, and navigate the document's data.
DOM IN A TREE STRUCTURE:
This is the tree structure implementation of an XML file.
● <table>
● <tr>
● <td>Mahesh </td>
● <td>Testing</td>
● </tr>
● <tr>
● <td> Second Line</td>
● <td> Tested</td>
● </tr>
● </table>
DOM TREE REPRESENTATION OF THIS XML:
In DOM, a document takes a hierarchical structure, which
is similar to a tree structure. The document has a root
node, and the rest of the document has branches and
leaves.
These nodes are defines as interfaces object. You use the
interfaces to access and manipulate document objects.
The DOM core API also allows you to create and populate
documents load documents and save them.
Manipulating files and the Registry
Manipulating Files
Folders
• The Path class is not a class that you would instantiate. Rather, it
exposes some static methods that make operations on path
names easier. For example, suppose that you want to display the
full path name for a file, ReadMe.txt in the folder C:\My
Documents. You could find the path to the file using the
following code:
• Console.WriteLine(Path.Combine(@"C:\My Documents",
"ReadMe.txt"));
• Using the Path class is a lot easier than using separation symbols
manually, especially because the Path class is aware of different
formats for path names on different operating systems. At the
time of writing, Windows is the only operating system
supported by .NET. However, if .NET were later ported to Unix,
Path would be able to cope with Unix paths, in which /, rather
than \, is used as a separator in path names. Path.Combine() is
the method of this class that you are likely to use most often,
but Path also implements other methods that supply
information about the path or the required format for it.
Moving, Copying, and Deleting Files
wrox-press-professional-c-5-0-and-net-4-5-1-
201
• On the other hand, the Windows Registry uses one logical repository that
is able to store user-specific settings. According to Microsoft, there are
several advantages over the obsolete .ini files like faster parsing, backup
or restoration.
• Structure of the Registry
• HKEY_CURRENT_USER
• This root element represents the currently logged-in user and
their specific settings. It is a link to a subkey of HKEY_USERS
that corresponds to the current user. It cannot be edited.
• HKEY_LOCAL_MACHINE
• HKEY_CURRENT_USER
• HKEY_USERS
• HKEY_LOCAL_MACHINE
• HKEY_CLASSES_ROOT
• HKEY_CURRENT_CONFIG
Each key has many subkeys and may have a value.
The operations on the registry in .NET can be done using
two classes of the Microsoft.Win32 Namespace: Registry
class and the RegistryKey class. The Registry class
provides base registry keys as shared public methods:
Deleting a Subkey
The following C# program shows how to create a registry entry , set values to
registry entries, retrieve values from registry and delete keys on Registry. Drag
and drop four buttons on the form control and copy and paste the following
source code.
using System;
using
System.Data;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs
e)
{
RegistryKey rKey ;
rKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
rKey.CreateSubKey("AppReg");
rKey.Close();
MessageBox.Show ("AppReg created !");
}
RegistryKey rKey ;
Object ver ;
string app = null;
rKey =
Registry.LocalMachine.OpenSubKey("Software\\AppR
eg", true);
app = (string)rKey.GetValue("AppName");
ver = rKey.GetValue("Version");
rKey.Close();
MessageBox.Show("App Name " + app + "
Version " + ver.ToString());
}
private void button4_Click(object sender, EventArgs
e)
{
RegistryKey rKey ;
rKey =
Registry.LocalMachine.OpenSubKey("Software", true);
rKey.DeleteSubKey("AppReg", true);
rKey.Close();
MessageBox.Show("AppReg deleted");
}
}
}
TRANSACTION
TRANSACTION
-- Table1
CREATE TABLE tblProject
(
ProjectID int PRIMARY KEY,
Name varchar(50) NULL
);
--Table2
CREATE TABLE tblProjectMember
(
MemberID int,
ProjectID int foreign Key references Project(ProjectID)
);
Often we use ADO.NET to perform Database opertaions. Here is the
sample code to implement transaction in ADO.NET.
objTrans.Commit();
}
catch (Exception)
{
objTrans.Rollback();
}
finally
{
objConn.Close();
}
}
SYSTEM TRANSACTION
• The property
• Current Current is a
static property
that doesn’t
require an
instance.
Transaction.Cu
• Isolation Level rrent returns an
ambient
transaction if
one exists..
• The
IsolationLevel
property
returns an
object of type
IsolationLevel.
IsolationLevel
is an
enumeration
that defines
what access
other
transactions
have to the
interim results
of the
transaction. ACID; not all
This reflects transactions
the “I” in are isolated.
• The TransactionInformation
property returns a
• Transaction Information TransactionInformation object,
which provides information about
the current state of the transaction,
the time when the transaction was
created, and transaction identifiers.
• TransactionCompleted is
an event that is fired when
the transaction is
completed—either
successfully or
unsuccessfully. With an
event handler object of
type
TransactionCompleted
EventHandler, you can
access the Transaction
object and read its status.
Committable Transactions:
•With ADO.NET, a transaction can be enlisted with the connection. To make this
possible, an AddStudentAsync method is added to the class StudentData that
accepts a System.Transactions .
Properties.Settings.Default.CourseManagementConnectionString);
await connection.OpenAsync();
try
{ if (tx != null)
connection.EnlistTransaction(tx);
SqlCommand command = connection.CreateCommand();
command.Parameters.AddWithValue("@LastName", student.LastName);
command.Parameters.AddWithValue("@Company", student.Company);
await
command.ExecuteNonQueryAsync();
finally
{ connection.Close();
}I
OUTPUT:
The transaction is active and has a local identifier. In addition, the user has
chosen to abort the transaction. After the transaction is finished, you can see
the aborted state:
TX created
Creation Time: 7:30:49 PM
Status: Active
Local ID: bdcf1cdc-a67e-4ccc-9a5c-cbdfe0fe9177:1
Distributed ID: 00000000-0000-0000-0000-000000000000
TX completed
Creation Time: 7:30:49 PM
Status: Aborted
Local ID: bdcf1cdc-a67e-4ccc-9a5c-cbdfe0fe9177:1
Distributed ID: 00000000-0000-0000-0000-000000000000
PROGRAM 2:
static async Task CommittableTransactionAsync()
{
var tx = new CommittableTransaction();
Utilities.DisplayTransactionInformation("TX created", tx.TransactionInformation);
try {
var s1 = new Student
{ FirstName = "Stephanie",
LastName = "Nagel",
Company = "CN innovation"
};
if ( Utilities.AbortTx() )
Utilities.DisplayTransactionInformation("TX completed",
tx.TransactionInformation); }
TX Created
Creation Time: 7:33:04 PM
Status: Active
n TX completed
• Provide and
consume data
• No centralized
data source
P2P (peer-to-peer):
• The primary goal of peer-to-peer networks is to share resources
and help computers and devices work collaboratively, provide
specific services, or execute specific tasks.
• P2P is used to share all kinds of computing resources such as
processing power, network bandwidth, or disk storage space.
• However, the most common use case for peer-to-peer networks
is the sharing of files on the internet.
• Peer-to-peer networks are ideal for file sharing because they
allow the computers connected to them to receive files and send
files simultaneously.
Why are peer-to-peer networks
useful?
Networking C#
Protocol (PNRP)
1 0 1 Virtual Global_
3 13 1 Virtual LinkLocal_ff00::%13/8
3 19 1 Virtual LinkLocal_ff00::%19/8
The output shows that three clouds are available: one is a global and two are link
local clouds. You can tell this from both the name and the Scope value, which is 3
for link local clouds and 1 for global clouds. To connect to a global cloud, you must
have an IPv6 address.
Clouds may be in one of the following states:
➤➤ Active: If the state of a cloud is active, you can use it to publish and resolve
peer names.
➤➤ Alone: If the peer you query the cloud from is not connected to any other peers, it
has a state
of alone.
➤➤ No Net: If the peer is not connected to a network, the cloud state may change
from active to no net.
➤➤ Synchronizing: Clouds are in the synchronizing state when the peer
connects to them. This state changes to another state extremely quickly because
this connection does not take long, so you will probably never see a cloud in this
state.
➤➤ Virtual: The PNRP service connects to clouds only as required by peer name
registration and resolution. If a cloud connection has been inactive for more than
15 minutes, it may enter the virtual state.
Clouds may be in one of the following states:
➤➤ Active: If the state of a cloud is active, you can use it to publish and resolve
peer names.
➤➤ Alone: If the peer you query the cloud from is not connected to any other peers, it
has a state
of alone.
➤➤ No Net: If the peer is not connected to a network, the cloud state may change
from active to no net.
➤➤ Synchronizing: Clouds are in the synchronizing state when the peer
connects to them. This state changes to another state extremely quickly because
this connection does not take long, so you will probably never see a cloud in this
state.
➤➤ Virtual: The PNRP service connects to clouds only as required by peer name
registration and resolution. If a cloud connection has been inactive for more than
15 minutes, it may enter the virtual state.
BUILDING P2P APPLICATIONS:
iv. Whether to generate endpoints for the peer name automatically. (The default
behaviour, where endpoints will be generated from the IP address or
addresses of the peer and, if specified, the port number.)
v. A collection of endpoints.
3. Use the peer name registration to register the peer name with the local PNRP
service.
After step 3, the peer name is available to all peers in the selected cloud (or
clouds). Peer registration continues until it explicitly stops, or until the process that
registers the peer name is terminated.
To create a peer name, you use the PeerName class.
After you have a PeerName instance, you can use it along with a port number
to initialize a PeerNameRegistration object:
Cloud.Global: This static property obtains a reference to the global cloud. This may
be a private global cloud depending on peer policy configuration.
Cloud.AllLinkLocal: This static field gets a cloud that contains all the link local clouds
available to the peer.
Cloud.Available: This static field gets a cloud that contains all the clouds available
to the peer, which includes link local clouds and (if available) the global cloud.
When created, you can set the Comment and Data properties if you want.
You can also add endpoints by using the EndPointCollection property. This
property is a System.Net.IPEndPointCollection collection of
System.Net.IPEndPoint objects. If you use the EndPointCollection property you
might also want to set the UseAutoEndPointSelection property to false to prevent
automatic generation of endpoints. When you are ready to register the peer name,
you can call the PeerNameRegistration.Start method.
To remove a peer name registration from
thewwPNwR.Prejisneprvaicuel,.cousme the PeerNameRegistration.Stop
method. The following code registers a secured peer name with a comment:
To resolve a peer name you must carry out the following steps:
1. Generate a peer name from a known P2P ID or a P2P ID obtained through a
discovery technique.
2. Use a resolver to resolve the peer name and obtain a collection of peer name
records. You can limit the resolver to a particular cloud and a maximum number of
results to return.
www.rejinpaul.com
3. For any peer name records that you obtain, obtain peer name, endpoint,
comment, and additional data information as required.
The simplest way to get a list of active peers in your link local cloud is for
each peer to register an unsecured peer name with the same classifier and
to use the same peer name in the resolving phase.
await Task.Delay(5000);
resolver.ResolveAsyncCancel(1);
}
Windows Presentation
Foundation (WPF)
• Windows Presentation Foundation (WPF) is a
library to create the UI for smart client
applications.
• It covers a large number of different controls and
their categories, including how to arrange the
controls with panels, customize the appearance
• using styles, resources, and templates, add some
dynamic behavior with triggers and animations,
and create 3-D with WPF.
Define WPF?
All these WPF elements can be accessed programmatically, even if they are buttons or
shapes, such as lines or rectangles. Setting the Name or x:Name property with the Path
element to mouth enables you to access this element programmatically with the variable
name mouth:
C# | Data Types
Data types specify the type of data that a valid C# variable can hold. C# is
a strongly typed programming language because in C#, each type of
data (such as integer, character, float, and so forth) is predefined as part
of the programming language and all constants or variables defined for a
given program must be described with one of the data types.
Data types in C# is mainly divided into three categories
● Value Data Types
● Reference Data Types
● Pointer Data Type
1. Value Data Types : In C#, the Value Data Types will directly store the
variable value in memory and it will also accept both signed and
unsigned literals. The derived class for these data types are
System.ValueType. Following are different Value Data
Types in C# programming language :
● Signed & Unsigned Integral Types : There are 8 integral
types which provide support for 8-bit, 16-bit, 32-bit, and 64-bit
values in signed or unsigned form.
DEFAULT
-32768 to
unsigned
unsigned
unsigned
unsigned
U +0000 to U
Example :
// C# program to demonstrate
// the above
data types
usingSystem;
namespaceVal
ueTypeTest {
classGeeksforGeeks {
//
Main
func
tion
stat
icvo
idMa
in()
{
//
declaring
character
chara =
'G';
shorts = 56;
ushortus = 76;
// this will give error as number is
// larger than short range
classGeeksforGeeks {
//
Main
func
tion
stat
icvo
idMa
in()
{
sbytea = 126;
// sbyte is 8 bit
// singned
value
Console.Wr
iteLine(a)
;
a++;
Console.WriteLine(a);
Output :
Example :
classGeeksforGeeks {
//
Main
func
tion
stat
icvo
idMa
in()
{
//
boolean
data
type
boolb =
true;
if(b == true)
Console.WriteLine("Hi Geek");
}
}
}
Output :
Hi Geek
Example :
// C# program to demonstrate
// the
Reference data
types
usingSystem;
namespaceValueT
ypeTest {
classGeeksforGeeks {
//
Main
Func
tion
stat
icvo
idMa
in()
{
//
declari
ng
string
stringa
=
"Geeks"
;
/
/
a
p
p
e
n
d
i
n
a
a
+
=
"
f
o
r
"
;
a =
a+"Geeks";
Console.Wr
iteLine(a)
;
//
declare
object
obj
objectobj
;
obj = 20;
Console.WriteL
ine(obj);
Example :
int* p1, p; // Valid syntax
int *p1, *p; // Invalid
Example :
classGFG {
//
Main
func
tion
stat
icvo
idMa
in()
{
unsafe
{
//
declare
variabl
e intn
= 10;