Consider the below example:
Posted on 28 September 2010.
Consider the below example:
Posted in C# FAQ6 Comments
Posted on 28 September 2010.
Order of Catch blocks is very importent while implementing the Catch Blocks.For Example if my code is expected to throw DivideByZeroException , If you know the exception type properly you have to write the specifice expected exception then write generic exception. See below example
Ex:
Posted in C# FAQ5 Comments
Posted on 28 September 2010.
Posted in C# FAQ0 Comments
Posted on 28 September 2010.
Q:Can i have access modifier for the get or set?
Ans: Yes you can but only for either for get or for set. You can define access modifiers for both get and set in a given property.
Ex:
Posted in C# FAQ0 Comments
Posted on 28 September 2010.
Properties in C# is a faster mechanism of reading and updating the private data. Properties generally considered as faster compared to methods . This is because for every instance method an entry will be created in the method table. Usually for CLR searching in method table is cumbersome and time consuming , hence Properties are faster.
GuideLine: See the article in msdn
http://msdn.microsoft.com/en-us/library/bzwdh01d(VS.71).aspx
Posted in C# FAQ2 Comments
Posted on 28 September 2010.
public interface Iphysics
{
int getsalary( int Empid);
}
public struct Campus : Iphysics
{
public string CampusName()
{
return “Palle Technologies Campus”;
}
public int getsalary(int Empid)
{
return 50000;
}
}
Posted on 27 September 2010.
Ref has to be initialized before calling the method. Out should be initialized after calling method i.e in the called method.See below Example.
Public Class Employee {
Posted in C# FAQ3 Comments
Posted on 27 September 2010.
Void pointers
===========
1. What is the use of void pointer ?
A. Void pointer for compiler means, compiler is not sure of to which data it is point to..
For example, int *i ==> means i is an object holds a pointer to a memory location which stores integer.
Lets take an example of a function where you are manipulating a memory location that may points
to any kind of data ( it may be int,float,struct etc .. ) . But you are not sure of which kind of pointer
user may pass with that function, then how you will code this generic function ?
Here comes the usage of void * .. Void pointer has the capability of storing any kind of pointer and retransmitting
it into corresponding pointer .. that means you can use this void pointer to take from a <specific pointer> and reassign
it to same <specific kind of pointer > ..
So your function prototype looks like this
void func( void *vPtr) { ……
…………
}
2. Can I perform arithmetic operation on void pointer ?
A. No You can’t perform arithmetic operation on void pointer.
3. Why I can’t perform arithmetic operation on void * ?
A. Because , since you can store any kind of pointer address into a void *, your compiler will not be sure
what kind of pointer you are going to store at run time. Which means to perform some operations on
pointer your compiler should know what kind of data type you are going to store in that memory location.
4. So can’t I perform arithmetic operations on void * ?
A. Yes you can perform if you know what kind of address you have initialized to that void *.
eg : int *i = Malloc(4 * sizeof(int));
void *vptr = i;
(int *)vptr + 1; // ==> will make sure that vptr will now points to second integer address.
5. Do I need to explicitly typecast while assigning void * to other pointers and vice versa ?
A. Not required , if you are not going to use it for c++ project also. Because C++ is very strict in typecasting.
But in C, it will do typecast for you automatically to other * type.
More on void pointer in later sections to follow…. Throw any kinds of doubts if you have..
Source of this article is Palle Technologies C training
Posted in C - Fresher questions, C Tutorials0 Comments
Posted on 24 September 2010.
Nested classes are the classes where the class declaration is fully implemented within the declaration of another class.
These are used mainly for developing object models in our component.
A nested class and the enclosing class might look like the following example:
public class Enclosingclass//this is enclosing class whose class declaration contains the nested class
{
public class Nested class
{
//implement the code of nested class
}
}
How to instantiate the nested class?
To instantiate the nested class in the previous example we can use the following syntax.
Enclosingclass.Nestedclass objNestedclass=new Enclosingclass.Nestedclass();
I hope this article will surely helps u.
Posted in C# FAQ2 Comments
Posted on 23 September 2010.
Interfaces in C# only contains only abstract members.and does not contain any fields or implementations.Consider the below scenario understand the Interfaces better.
Ex: Palle technologies having a .net team of 10 developers and got an order to develop the software for a multi bed hospital.
Here the classes involved in this applicatiosn is Doctor,Nurse,Compounder,Surgeon,Physician. All these classes has to give the salary details .So Palle technologies asked the developers to implement the classes.
Developer 1: implementing class Doctor
Public Class Doctor { //writing functionality for getting salary . public int returnSalary(string doctorid) {return sal;}}
Developer 2: Implementing Class Nurse
Public Class Nurse { //implement salary logic. public int getSalary(string nurseId){ return sal;}}
like this all the developers are trying to write the methods which is having similar functionality but with different names. This kills the program or code readability and maintainability. to get rid of this. Implement the Interface called “IEmployee”
Ex: Public interface IEmployee
{int getsal(string empid);}
Classes: Public Class Doctor:IEmployee {//implement the getsal }
Public Class Nurse:IEmployee{//Implement the getSal;}

Latest Comments