C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg.
C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages to be used on different computer platforms and architectures.
1.What is object-oriented programming (OOP) Language?
Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
bool, byte , char, decimal , double, float, int, long, sbyte , short, uint, ulong, ushort.
3. Explain about C# Language.
C# is a OOPs language, .net framework use to compiled it, to generate machine code.
4.Top reason to use C# language?
Modern, general-purpose programming language
Object oriented.
Component oriented.
Easy to learn.
Structured language.
It produces efficient programs.
It can be compiled on a variety of computer platforms.
Part of .Net Framework.
5.Feature of C# language?
Boolean Conditions
Automatic Garbage Collection
Standard Library
Assembly Versioning
Properties and Events
Delegates and Events Management
Easy-to-use Generics
Indexers
Conditional Compilation
Simple Multithreading
LINQ and Lambda Expressions
Integration with Windows
6. Types of comments in C#?
Single line comments
// for single line comments
Multiple line comments
/* for multi line comments */
XML tags comments
/// XML tags displayed in a code comment
7.What is a Class?
a set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality.
8. What is object?
Objects are created from Classes, in C#, is an instance of a class that is created dynamically. Object is also a keyword that is an alias for the predefined type System.
9.What is Constructors, explain with syntax
A is special method of the class that will be automatically invoked when an instance of the class is created is called as constructor.
Constructors are mainly used to initialize private fields of the class while creating an instance for the class.
When you are not creating a constructor in the class, then compiler will automatically create a default constructor in the class that initializes all numeric fields in the class to zero and all string and object fields to null.
Syntax.
[Access Modifier] ClassName([Parameters])
{
}
EX
10.Types of Constructors
1.Basically constructors are 5 types those are
2.Default Constructor
3.Parameterized Constructor
4.Copy Constructor
5.Static Constructor
6.Private Constructor
All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies.
public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private: The type or member can be accessed only by code in the same class or struct.
protected: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.
The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.
In Overriding methods it will create two or more methods with same name and same parameter in different classes.
while Overloading it will create more then one method with same name but different parameter in same class.
14.What is Static Classes?
A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated.
In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself.
A non-static class can contain static methods, fields, properties, or events.
The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
First element is 0 (zero). In a Array.
c)Polymorphism.
Because structures are mainly used for light weight process.
Yes structs can inherit only from interface.
a)Make the class as sealed.
b)Add private constructors to the class.
If you mark a class as sealed it means that you cannot inherit from it but you can create objects of that class.
Yes.But for a method to be marked as sealed you need to have override keyword also.
class DerivedClass :BaseClass
Upcasting--assigning a derived class object to a base class.
Downcasting--assigning baseclass object to derived class.
-The access is provided only as required.
-It prevents other objects from altering or accessing the properties of an encapsulated object.
40. Explain: a.) Static binding b.) Dynamic binding
It is a binding in which the name of the class can be associated with it during compilation. Also referred to as early binding.
b.) Dynamic binding –
It is a binding in which the name of the class can be associated with it during execution time. Also referred to as late binding.
The abstract keyword can be used with classes, methods, properties, indexers and events.
-- By making method access specifier public
-- use the Java Beans Getter/setter method instead of constructor
103.Difference between "throw" and "throw ex" in .NET
it is very important to just use the throw statement, rather than throw ex because it will give you more accurate error stack information.
104.Difference between IS and AS operators in C# The is operator checks whether an object is compatible with a given type, and the result of the evaluation is a Boolean: true or false. The is operator will never throw an exception. An is expression evaluates to true if both of the following conditions are met: expression is not null expression can be cast to type The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form: Employee e = obj as Employee; is equivalent to: Employee e = obj is Employee ? ( Employee)obj : ( Employee)null;
105.What is a COPY Constructor?
|
0 comments:
Post a Comment