answersLogoWhite

0

C Sharp

C Sharp is a programming language developed by Microsoft Corporation. It is designed to be a simple, general-purpose, modern, object-oriented programming language. The latest version is C# 4.0. It is designed for developing applications for both embedded and hosted systems.

343 Questions

Why the .net is platform dependent?

Ya .Net is platform independent as well as dependent.

Once the code is written , it is then compiled into MSIL (Microsoft Intermediate Language) which is independent of platform, here the CLR (Common Language Runtime) comes into picture and it consists of JIT(Just In Time)compiler which is going to convert the MSIL code into platform/device specific code. So We have CLR for Windows and CLR for Linux. Here its dependent of the type of machine its running on. So its Dependent.

Why run time polymorphism is dynamic and compile time polymorphism is static?

The simple answer is that compile-time polymorphism occurs at compile time while runtime polymorphism occurs at runtime.

The actual answer is that compile-time polymorphism results in the compiler generating source code on your behalf while runtime polymorphism relies on function pointers or virtual methods to determine the next instruction at runtime.

Compile-time polymorphism therefore applies to template functions and classes since that is the only way the compiler can generate source code on your behalf. To achieve this, the runtime type for the template parameters must be fully-defined at compile time, even if those types have runtime polymorphic characteristics of their own.

Runtime polymorphism applies to virtual methods and function pointers, both of which can be used to dynamically alter the execution path of your program. Virtual methods are made possible through virtual tables, which are essentially just arrays of function pointers. Each runtime type that derives from a base class with virtual methods provides its own virtual table, thus the runtime type determines which specific function overrides will be invoked at runtime, even if the runtime type cannot be determined at compile time. In this way you can generalise your code to work with the base type but still get the expected polymorphic behaviour whenever a derived type is passed instead.

What is override keyword in c sharp?

Operator Overloading is a Polymorphism concept. Standard unary and binary operators like (+, -, *, /, %, &, |, <<, >> ) have a predefined implementation that describes their behavior when applied on operands. However using operator overloading we can provide additional meanings to these operators.

For example we can add two integers using a + b. However the + operator cannot be used to add two objects for example two vectors. For this we need to overload the operator '+' so as to implement it toadd two vector objects.

refer related links for having a look at the example.

What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods.

We cannot create an object for the abstract classes.

When we inherit the abstract class we should implement the abstract method which we inherit.

What are some sharp objects?

Examples: knife, sword, ax, guillotine, blade, razor, scalpel, scissors etc.

Write a program find greatest no between three no?

public class MathExtension {

public static decimal getGreatest(decimal d1, decimal d2, decimal d3) {

decimal temp = Math.Max(d1, d2);

return Math.Max(temp, d3);

}

}

caller:

Console.WriteLine(MathExtension.Extension(2m, 3m, 1m)); // prints 3 on console)

How do you inherit from class in c?

struct SClass{

int iNumber;

int (*fpgetValue)();

int (*fpsetValue)();

}Sc;

int m_Func(){

printf("\n\n Hello How are you doing,i called by function pointer");

getchar();

return 1;

}

int _tmain(int argc, _TCHAR* argv[])

{

Sc.fpgetValue=m_Func;

Sc.fpgetValue();

return 0;

}

Write a c plus plus program that inputs 5 integers from the user and separates the integer into individual digits and prints the digits separated from one another by three spaces each.?

// create an BufferedReader from the standard input stream

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String currentLine = "";

int total = 0;

int[] ints = new int[5];

// read integers

while (total < 5) {

// get input

System.out.print("Input an integer: ");

currentLine = in.readLine();

// parse as integer

try {

int input = Integer.parseInt(currentLine);

ints[total] = input;

++total;

} catch (final NumberFormatException ex) {

System.out.println("That was not an integer.");

}

}

// print each number

for (int i = 0; i < ints.length; ++i) {

// get individual digits

if (ints[i] == 0) {

System.out.println(0);

} else {

while (ints[i] > 0) {

System.out.println(ints[i] % 10);

ints[i] /= 10;

}

}

}

Note that this prints out the digits in reverse order (2048 will print 8 first and 2 last).

Why c is preferred over Java for embedded system?

Embedded systems typically run on extremely limited hardware. Even the smallest implementation of Java (Micro Edition) can't compete with a small C implementation both in terms of memory footprint and execution speed.

What is the major difference in class and interface in c?

The implementation detail. Classes may provide a default implementation, interfaces provide only the method signatures

What are the advantages and disadvantages of arrays in c sharp?

Advantages:

1. Can store "n" number of same data types in different indexes

2. Can be accesses using reference.

Disadvantage:

1. No boundary check, if the array boundary is crossed run time

2. No facility to increase the size of array in Run time

When do you give preference to abstract classs and interface?

Abstract class provides a way of "being a [something like me]", or inheritance

interface provides a set of functionality (contract) as "behaving".

Abstract class provides the single inheritance and perhaps some default implementation, while interface may be implemented by different classes that have nothing to do one and other except the common interface implementation.

The preference I would start with:

Ask yourself that an object should be "Is a something or behave like something". If your answer is "Is a", then abstract class is more likely your good choice. But if your answer is behave like, does not need to Is a, then the interface is the way to go.

How do you convert a doc file into a pdf file using C sharp code?

Originally, a full version of Adobe's Acrobat application was required to create PDF (Portal Document Format) files from any application, including Microsoft Word. Subsequently, a number of companies sold inexpensive PDF conversion software to compete with the more expensive Adobe product. These applications, like Acrobat, used a printer driver to "print" Postscript-based PDF files. The Mac OS central window server caches window graphics in PDF, allowing any Macintosh application to print to a PDF file from within the OS.

Today, all current versions of Microsoft Word will save directly into PDF format. There's no need to use Visual Basic, assuming you have Microsoft Word.

You can create PDF files programmatically in VB6. You'll need the mjwPDF class and the appropriate PDF fonts. A tutorial on the subject has been attached to this page as a related link: Tutorial - Create PDF files with VB6

Inaddition, you also can use enolsoft PDF Creator to do that. It's fast and simple yet.

What is expansion of DOT in dot net language?

.NET- NETWORK ENABLED TECHNOLOGY

here . stands for LINKAGE BETWEEN MANY OBJECTS

Is c sharp a case sensitive language?

Yes.

The upper/lower case chars are regarded as being different in C.

For example, you can have two variables, one called 'x' and the other called 'X' and the compiler will recognize them as separate variables.

Write a program to print first 'n' Fibonacci 100 numbers?

#include<stdio.h> #include<conio.h> void fibo(int); void main() { int num; clrscr(); printf("\n\t Enter number of elements in series : "); scanf("%d",&num); if(num>0) fibo(num); else printf("\n\t Please enter positive number "); } void fibo(int num) { int a=0,b=1,c=0; if(num==1) printf("\n%d",a); if(num>=2) printf("\n%d\t%d\t",a,b); for(;num>2;num--) { c=a+b; a=b; b=c; printf("%3d\t",c); } getch(); }

What is the difference between Late binding and early binding?

Early binding. The type of the instance is determined in the compile time. It follows that the static (declared) type of the pointer or reference is used. This is the default for all methods in C++, C, or Object Pascal.

Late binding. The type of the instance is determined in the run time. It follows that the actual type of the instance is used and the method of this type is called. This is always used for the methods in Java. In C++, the virtual keyword denotes the methods using the late binding.

Late binding gives the class polymorphic behavior. On the other hand, late binding is less effective than early binding, even though the difference may be negligible. (In C++ on PCs, the difference between the late and the early binding is usually one machine instruction per method call.)

Any method that might be overridden in any of the derived classes should use the late binding.

Note:

In C++ and other OOP languages in which the late binding must be declared, the classes containing at least one virtual method are called polymorphic classes. Classes without any virtual method are called non-polymorphic classes. In languages like Java, where all the methods use late binding by default, all the classes are polymorphic.

What is the best way to learn C sharp?

I am a C sharp student right now learning to code.

I first tried to learn with books like C# for Beginners and stuff like that, but it didn't really work out. In my opinion, the best way to learn C sharp is if you learn it from any teacher. It could be you uncle, father, brother, or a certified teacher. That is better than learning it by yourself from a book. To become an expert you should try to find free projects to do on the internet which will really boost you in programming and you will be ahead of the rest.

What are the differences between class and abstract class?

Below is the main difference between the 3 components:

  • Concrete class - Provides implementation for all its methods & also for methods from extended abstract classes or implemented interfaces
  • Abstract class - Does not provide implementation for one or more of its methods
  • Interface - Does not provide implementation for any of its methods

Write a program that accepts a number and output its equivalent in words?

/*mycfiles.wordpress.com
program to convert digits to character*/
#include
#include
void main()
{
int a[5],i,n;
clrscr();
cout<<"Enter the Value";
cin>>n;
for(i=4;i>=0;i--)
{
a[i]=n%10;
n=n/10;
}
for(i=0;i<5;i++)
{
if(a[i]!=0)
{
switch(a[i])
{
case 0:cout<<"Zero";
break;
case 1:cout<<"One";
break;
case 2:cout<<"Two";
break;
case 3:cout<<"Three";
break;
case 4:cout<<"Four";
break;
case 5:cout<<"Five";
break;
case 6:cout<<"Six";
break;
case 7:cout<<"Seven";
break;
case 8:cout<<"Eight";
break;
case 9:cout<<"Nine";
break;
}
}
}
getch();
}


------------------------------------------------------------------------------------


Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

Program to Convert Numbers into Words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}


// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"

What do you mean by managed and unmanaged code in net?

"Unmanaged code" is a new name for an old concept. Unmanaged code stands for native machine code. Software is typically written in some high-level language such as Pascal, C or C++. These languages are translated into machine code (aka unmanaged code) by the compiler and its companion tools (assembler, linker, librarian, etc). The generated code runs natively on the host processor; that is, the processor directly executes the code generated by the compiler. This approach typically results in fastest code execution, but diagnosing and recovery from errors might be easier in managed code. Managed code is a new name, but the concept also is pretty old. Today, "managed code" typically stands for the system used by Microsoft .NET, but .NET is just one example of a managed code system. The .NET system takes source code in any of the supported languages (which include C, C++, C#, Pascal, and many others), and translates it into code designed for a virtual machine. The real processor cannot execute this code natively, but it can execute a program which then in turn executes the virtual machine's codes. The program that executes the virtual machine code is known as the virtual machine. While potentially slower than native code execution, the virtual machine can manage code (!) better than real machines. For example, the virtual machine can supervise memory allocation, automatically handle disposal of unused memory, and provide many other services that a native (unmanaged) application typically must explicitly provide. If the virtual machine does its job correctly, all applications using this virtual machine are likely to benefit. Virtual machines are also known under other names. In the Java system, the tool is called a JVM, a Java Virtual Machine. In the Microsoft .NET system, the intermediate language is called MSIL (Microsoft intermediate language), which are executed through a Just-in Time MSIL compiler (JIT-compiler). Early implementations of Pascal generated an intermediate code called P-code, executed at runtime through some P-code interpreter. Other forms of managed code exist.

What are inner classes?

Quite simply, an inner class is one class within another. Typically the inner class will be a private inner class, and will only be used by the outer class.

class MyOuterClass {

class MyInnerClass {

}

}

Why should main be declared static and is declaring it public and void not sufficient?

The static modifier means that it does not have to be instantiated to use it. Before a program runs there are technically no objects created yet, so the main method, which is the entry point for the application must be labeled static to tell the JVM that the method can be used without having first to create an instance of that class. Otherwise, it is the "Which came first, the chicken or the egg?" phenomenon. Your main method should be declared as follows: public static void main (String[] args) { lots of your java code... } As we know, java is a pure OOP , that means everything should be in the class, main. Aso, because main is itself a function, static member functions should not refer to objects of that class. But we can access static functions through classname itself, as: class TestMain { public static void main(String args[]) { body; } } Now, cmd>javac TestMain.java cmd>java TestMain as we know the static member functions has to call through its class name. That's why the programme name must be same as the class name ,where we wrote the main function. Another important point is : static variables or member functions will load during class. That means before creating any instances(objects), the main function is the first runnable function of any program which we run manually, such as : cmd>java TestMain(run) if , any sharing information.

What is difference between abstract class and interface in core java give brief answer with example?

Differences:

  1. Abstract class can also contain method definitions but an interface can contain only declarations
  2. All variables in an interface are by default public static and final whereas in Abstract class it is not

An interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.