Assignment OF Modern Programming Tools and Techniques-II
Assignment OF Modern Programming Tools and Techniques-II
OF
Modern Programming Tools
and Techniques-II
B.TECH(H)-MBA(CSE)
ROLL NO.- 17
SECTON-RA17B1
Q-1 What standard data types does C Sharp use? Contrast it
with the types in C++?
Ans- C# supports a very similar range of basic types to C++, including int, long,
float, double, char, string, arrays, structs and classes. However, don't assume too
much. The names may be familiar, but many of the details are different. For
example, a long is 64 bits in C#, whereas in C++ the size of a long depends on the
platform (typically 32 bits on a 32-bit platform, 64 bits on a 64-bit platform). Also
classes and structs are almost the same in C++ - this is not true for C#. Finally,
chars and strings in .NET are 16-bit (Unicode/UTF-16), not 8-bit like C++.
The C++ programming language identifies five data types as standard data types:
Void
Boolean
Character
Integer
Floating-point
The standard data types and the complex data types within C++ have a series of
attributes, which include:
Operations Allowed – i.e. Which operators can I use on the data type
Ans- Yes.
using the params keyword. The arguments are specified as a list of arguments of a
specific type, e.g. int. For ultimate flexibility, the type can be object. The standard
example of a method which uses this approach is System.Console.WriteLine().
The params keyword can be applied to a method parameter which is an array. Upon
method invocation, the array elements can be supplied as a comma (,) separated list.
For example, if the method parameter were an array of object, the source code would
be similar to the following:
void paramsExample
(object argument-1,
object argument-n,
params object[ ] variableArguments)
{
foreach (object arg in variableArguments)
{
}
}
but in case of constant variables once assign a value we can't change value and must
assign value to constant variables at the time of declaration.
as the constant variable is constant over the class,that means,all the objects created for
that class have the same value.
but in case of readonly variables,we can assign different values in the different
instances of the class it contains.
Const – Compile-Time Constant Values
First of all, for those of you who came from the C++ and C# world, const in C# is not the
same as const in that language. A const in C# can be closest considered like
a #define of a literal value (that is, a value, not a code macro). Const in C# let's you
define constant values. In C#, you can declare a const of any type as long as the value
assigned can be fully evaluated at compile time. For the most part, this limits you to
numeric types, characters, and strings:
Notice that up above, you can concatenate strings or do math on numbers to make new
constant literals. This works because these expressions can be determined at compile
time. However, notice thatstring.Empty is not a const field, it is a static readonly
instance, thus it will not allow this to be assigned to a const because it's not a literal
expression.
Now, remember how I said ANY type as long as the value can be evaluated at compile-
time. This means that const structs, are impossible because a struct must always call
its constructor first to initialize it. Therefore you cannot have a const struct of any value.
Q- What is the difference about Switch statement in C Sharp from C++ and C?
Ans- It was a surprise that there was no thread for C++ recipes. Though C++ and C#
are quite similar there are some very key and major differences.
-I find C# resembles the style of java more than that of C++ i many ways.
(I will be following this up with some coding recipes, to hopefully start a C++ reciped
thread)
Method/Function Declarations:
C++:
public:
Constructor() { }
void aMemberFunction() { }
void aFunctionDeclaration();
private:
void someOtherFunction() { }
int aVariable;
C#:
private aVariable;
public void aMemberFunction() { }
public void aFunctionDeclaration();
private void someOtherFunction() { }
Class Declaration:
For those who know what a managed class is:
C++:
__gc class A_Class{ };
*NOTE that C++ classes end with a ;
C#:
automatically done so:
class A_Class{ }
Inheritence:
C++:
will allow multiple inheritence. eg. allows a method to be overriden many times in
subclasses (derived classes).
C#:
supports inheritence, but not multiple, only 1 override per method/function/
Includes:
SYNTAX-
selection-statement:
switch (expression)statement
labeled-statement:
case constant-expression : statement
default : statement
switch ( expression )
declarations
.
case constant-expression :
.
break;
default :
To override a method in the derived class declare the function virtual in the base class.
We'll begin with a base class that represents an employee. To keep the example as
simple as possible, we'll give this base class a single method called CalculatePay with
the body of this method doing nothing more than letting us know the name of the
method that was called. This will help us determine which methods in the inheritance
tree are being called later.
class Employee
{
public void CalculatePay()
{
Console.WriteLine("Employee.CalculatePay()");
}
}
new public void CalculatePay()
{
Console.WriteLine("SalariedEmployee.CalculatePay()");
}
}
class Poly1App
{
public static void Main()
{
Poly1App poly1 = new Poly1App();
c:\>Poly1App
Employee.CalculatePay()
Salaried.CalculatePay()