0% found this document useful (0 votes)
2 views4 pages

C# 2

The document provides an overview of various C# programming concepts including enums, partial classes, sealed classes, generics, tuples, lambda expressions, constants, parameters, array manipulation, exception handling, value and reference types, namespaces, return types, binding types for WCF services, IEnumerable and IQueryable interfaces, the Singleton design pattern, and lazy initialization. Each concept is briefly explained with examples and key characteristics. The document serves as a reference for understanding fundamental C# features and design patterns.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

C# 2

The document provides an overview of various C# programming concepts including enums, partial classes, sealed classes, generics, tuples, lambda expressions, constants, parameters, array manipulation, exception handling, value and reference types, namespaces, return types, binding types for WCF services, IEnumerable and IQueryable interfaces, the Singleton design pattern, and lazy initialization. Each concept is briefly explained with examples and key characteristics. The document serves as a reference for understanding fundamental C# features and design patterns.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Enum :
Enum is used to assign constant names to a group of numeric integer values. It
makes constant values more readable,
Ex: Apptype ,Logtype

2.Partial classs :
1.A partial class is a special feature of C#.
2.It provides a special ability to implement the functionality of a single class
into multiple files and all these files are
combined into a single class file when the application is compiled.
3.A class have multiple bodies ,but these bodies are implementing diffrent
operations.
4.A partial class is created by using a partial keyword.

3.Sealed Class :
Sealed class is used to stop a class to be inherited.

4.Generics :
1.generic means not specific to a particular data type.
2.C# allows you to define generic classes, interfaces, abstract classes, fields,
methods, static methods,
properties, events, delegates, and operators using the type parameter and
without the specific data type.
3.A type parameter is a placeholder for a particular type specified when
creating an instance of the generic type.

generic Constraint :
1.new
2.class
3.struct
4.unmanaged

Syntax:
A generic type is declared by specifying a type parameter in an angle brackets
after a type name, e.g. TypeName<T>
where T is a type parameter.

Collections:
specialized class for datastorage and retrival
lists
stack
quee
hashset

5.C#-Tuple :
1.The Tuple<T> class was introduced in .NET Framework 4.0. A tuple is a data
structure that contains a sequence of elements
of different data types.
2.It can be used where you want to have a data structure to hold an object with
properties,
but you don't want to create a separate type for it.

6.Lambda expressions:
1.Lambda expressions in C# are used like anonymous functions, with the difference
that in Lambda expressions you don’t need
to specify the type of the value that you input thus making it more flexible to
use.
2.The ‘=>’ is the lambda operator which is used in all lambda expressions.
3.The Lambda expression is divided into two parts, the left side is the input and
the right is the expression.

7.Constant,Static and ReadOnly :


1.Constant : its a field or local variable once you declared cannot modify the
excution completed.
2.Static : copy of the object need to share among all the instances . whenever
change the static value last maodified
value available for excution.
3.Readonly : Field can be initialized at the time of declaration(or) within the
constructor of the same class.its used
to runtime constants.

8.Types of parameter:
1.ref parameter
2.out parameter
3.optional parameter
4.Default parameter
5.dynamic parameter
6.value parameter

9.Arry clone and Copy :


Array Clone : Shallow Copy of array.It copies all the element of array weather
reference type or value type not an object.
Array Copy : Copies all the range value one array to another onediemenssional
array.

10.Exception handling:
Complie time Error : Syntax Error
Runtime Error : Logical Mistake it means Variable of the data contains
values.
Types:
System.OutOfMemoryException.
System.NullReferenceException.
System.InvalidCastException.
System.ArrayTypeMismatchException.
System.IndexOutOfRangeException.
System.ArithmeticException.
System.DevideByZeroException.
System.OverFlowException.

11.Value and Reference Type :


value Type : Holds the Data Value in Own Menmory Space.Ex:
int,bool,cahr,short...
Refernece Type : Its does't stores the values directly,it stores address where
value being stored.Ex:string ,string array,class...

12.Name Space :
Logical Container of the grouping items.default project name as namespace.

13.return types in c#;


ref parameter
out parameter
returning array
returning a tuple

14.Basic binding:
-- HTTP protocol to transport and represent a WCF service as an ASP.NET web
service (ASMX web service)
-- that old clients who use ASMX web services can consume the new services
conveniently.
Web Service Binding :
-- Same as Basic Binding ,uses the same protocols for transport
-- but offers several WS–* specifications such as WS–Reliable Messaging,
WS–Transactions, WS–Security,
IPC Binding :
-- its name Pipe Binding
-- fastest binding and the most secure one amidst all the available bindings
-- message-level security is not supported here, messages are secure by
default because of a robust transport security
TCP Binding:
--NetTCPBinding
-- TCP protocol for communication within the same network
-- message encoding in binary format,Most Relaibale
Web binding:
-- WCF services in the form of HTTP requests by the use of HTTP-GET, HTTP-
POST,
-- It is offered by the WebHttpBinding class and is used commonly with social
networks

15.IEnumerable
--will enumerate all elements,this case IEnumerable will iterate all elements
--IEnumerable is great for working with in-memory collection
--AsEnumerable() method is used to convert/cast specific types of given list
items to its IEnumerable equivalent type.

16.IQueryable :
--while will enumerate elements based on query only,IQueryable will use Top 1
as a clause to fire a query
--IQueryable<t> allows for a remote data source, like a database or web service
--IQueryable is suitable for querying data from out-memory (like remote
database, service) collections. While querying data from a database,
-IQueryable executes a "select query" on server-side with all filters.
IQueryable is beneficial for LINQ to SQL queries.

17.Singleton Design:Creational Design pattern


-Only one Object Creation
-Every Object has Specific thing in no Singleton.
ex:Student Test1=new Student(1,100);
Student Test2=new Student(1,200);
Here Student Object has specfic property ,Both Test1 ,Test2 has student
property,here singleton not used.
Purpouse: if we want to use common things menas we can use Singleton.

Adv :
-- Saves Memmory ,Performance improvement.

Step 1: Create a private static Sigleton --> You cannot access outside the World .
Step 2:Here we have used Private constructor.
step 3: Without Private Constructor we cannont implement the Singleton Design
pattern .(Creat a static Method get a instance)

Class File :
public class Sigleton{

private static Singleton singleton;


private Singleton ()
{
}
public static Singleton getinstance()
{
if(singleton ==null)
{ --> Here first time the instace will created, next check the null conditiion
the same object will created .
singleton=new singleton();
}
retunrn singleton ;
}
}

cs.File :Namespace file

public static void main ()


{
Singleton sin1=new Singleton.getinstance();
Singleton sin2=new Singleton.getinstance();
}

-- one of the most common design patterns is software design


--singleton design pattern ensures a class has only one instance in the program and
provides a global point of access to it
--A singleton is a class that only allows a single instance of itself to be created
and usually gives simple access to that instance

Real Time Example : Printing Machine, DataBase Connection Class,Error Logger Class

18.Implementation:
A single constructor, that is private and parameterless.
The class is sealed.
A static variable that holds a reference to the single created instance, if
any.
A public static means of getting the reference to the single created
instance, creating one if necessary.

19.Thumb rule for a Singleton:


1.Declare a private constructor for a class.
2.Declare a static member for a class.
3.Create a static method for a class .

20.Lazy Initialization:
1.avoid creating the object completely if you never need it.
2.when we invoke the get instance of a class only singleton object
created.Delay of singleton instance creatoin
is Lazy initialization.
3.Ex : Grid rows Showing.First Click Shows 10 records ,2nd Click Shows Next 10
records.

You might also like