Florence Blogspot about asp.net tutorials and web design and web development

Tuesday, January 22, 2008

C# Frequently asked questions

FAQ Questions
What is C#?
Does C# replace Java?
Does C# replace C++?
What does a simple C# program look like?
Is C# object-oriented?
Does C# have its own class library?
How do I develop C# apps?
Are there any free C# IDEs that I could use?
Can I program 3D games with C#?
What is Common Language Runtime (CLR)?
What is boxing and unboxing?
Are there pointers in C#?
What are delegates?
Are there Certification exams for C#?
Can I use MySQL with C#?
Can I use DirectX in C#?
Is it possible to have a static indexer in C#?
Can I use inline assembly or IL in C# code?
Does C# have macros or a preprocessor?
Does C# have templates like C++?
Why can't I use static and const together?

FAQ Answers

Q: What is C#?

A: C# is a programming language designed by Microsoft. It is loosely based on C/C++, and bears a striking similarity to Java in many ways. Microsoft describe C# as follows:"C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++. C# (pronounced 'C sharp') is firmly planted in the C and C++ family tree of languages, and will immediately be familiar to C and C++ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C++."

Q: Does C# replace Java?
A: C# is a very Java-like language - the core of both languages have similar advantages and limitations when compared to C++. For example, both languages have garbage collection, but neither language has templates. Microsoft have ceased production of Visual J++, so it's hard not to view C# as Microsoft's alternative to Java.

Q: Does C# replace C++?
A: The obvious answer is no. However it's difficult to see C++ as the best choice for new .NET code. For the .NET runtime to function fully, it requires the programming language to conform to certain rules - one of these rules is that language types must conform to the Common Type System (CTS). Unfortunately many C++ features are not supported by the CTS - for example multiple inheritance of classes and templates.Microsoft's answer to this problem is to offer Managed Extensions (ME) for C++, which allows you to write C++ that conforms to the CTS. New keywords are provided to mark your C++ classes with CTS attributes (e.g. __gc for garbage collection). However, it's difficult to see why ME C++ would be chosen over C# for new projects. In terms of features they are very similar, but unlike C++, C# has been designed from the ground-up to work seamlessly with the .NET environment. The raison d'etre for ME C++ would therefore appear to be porting existing C++ code to the .NET environment.So, in answer to the question, my suspicion is that C++ will remain an important language outside of the .NET environment, and will be used (via ME) to port existing code to .NET, but I think C# will become the language of choice for one-time C++ developers developing new .NET applications. But only time will tell ...


Q: What does a simple C# program look like?
A: This is the Hello World program:
class CApplication
{
public static void Main()
{
System.Console.Write( "Hello, new .NET world." );
}
}

Q: Is C# object-oriented?
A: Yes, C# is an OO language in the tradition of Java and C++.

Q: Does C# have its own class library?
A: Not exactly. In common with all .NET languages (e.g. VisualBasic?.NET, JScript.NET) C# has access to the .NET class library. C# does not have its own class library.

Q: How do I develop C# apps?
A: The (free) .NET SDK contains the C# command-line compiler (csc.exe). Visual Studio.NET has fully integrated support for C# development. You need to download the .NET SDK and then whatever compiler or IDE you'd like to use.Q: Are there any free C# IDEs that I could use?

Q: What is Common Language Runtime (CLR)?
A: As part of Microsoft's .NET Framework, the Common Language Runtime (CLR) is programming that manages the execution of programs written in any of several supported languages, allowing them to share common object-oriented classes written in any of the languages. The Common Language Runtime is somewhat comparable to the Java virtual machine that Sun Microsystems furnishes for running programs compiled from the Java language. Microsoft refers to its Common Language Runtime as a "managed execution environment." A program compiled for the CLR does not need a language-specific execution environment and can easily be moved to and run on any system with Windows 2000 or Windows XP.Programmers writing in any of Visual Basic, Visual C++, or C# compile their programs into an intermediate form of code called Common Intermediate Language (CIL) in a portable execution (PE) file that can then be managed and executed by the Common Language Runtime. The programmer and the environment specify descriptive information about the program when it is compiled and the information is stored with the compiled program as metadata. Metadata, stored in the compiled program, tells the CLR what language was used, its version, and what class libraries will be needed by the program. The Common Language Runtime allows an instance of a class written in one language to call a method of a class written in another language. It also provides garbage collecting (returning unneeded memory to the computer), exception handling, and debugging services.

Q: What is boxing and unboxing?
A: Boxing and unboxing is a essential concept in C#’s type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can ultimately be treated as an object. Converting a value type to reference type is called Boxing. Unboxing is an explicit operation.

Q: Are there pointers in C#?
A: There are no pointers in the C# language, although you can use pointers in your C# applications, as long as you put them into the "unsafe code" space:…
unsafe
{

// unsafe context: can use pointers here

}


Q: What are delegates?
A: A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure.


Q: Are there Certification exams for C#?
A: Yes, in fact, there already are 3 exams, 70-315, 70-316, and 70-320. Check these links for more information.http://www.microsoft.com/traincert/exams/70-315.asphttp://www.microsoft.com/traincert/exams/70-316.asphttp://www.microsoft.com/traincert/exams/70-320.asp

Q: Can I use MySQL with C#?
A: Yes, you can use MySQL with C#.You can connect to the database by using ODBC driver and the System.Data.Odbc namespace.

Q: Is it possible to have a static indexer in C#?
A: No, they are not allowed in C#.

Q: Can I use inline assembly or IL in C# code?
A: No.

Q: Does C# have macros or a preprocessor?
A: C# doesn't have macros as such, nor does it strictly speaking have a pre-processor, but it does have conditional compilation symbols which can be used to affect compilation. These can be defined within code or with parameters to the compiler. The "pre-processing" directives in C# (named solely for consistency with C/C++, despite there being no separate pre-processing step) are (text taken from the ECMA specification):#define and #undefUsed to define and undefine conditional compilation symbols#if, #elif, #else and #endif Used to conditionally skip sections of source code#line Used to control line numbers emitted for errors and warnings.#error and #warning Used to issue errors and warnings.#region and #endregion Used to explicitly mark sections of source code.See section 9.5 of the ECMA specification for more information on the above. Conditional compilation can also be achieved using the Conditional attribute on a method, so that calls to the method will only be compiled when the appropriate symbol is defined. See section 24.4.2 of the ECMA specifcation for more information on this.

Q: Does C# have templates like C++?
A: Although C# doesn't have templates, and isn't likely to get them, it is getting a feature called generics which will be available in Whidbey, the next version of .NET, which should be available in the first half of 2005. (A beta version is currently available.) Generics will be a feature in the CLR itself, and most languages targetting the CLR will change to support it. Generics provide a lot of the functionality of C++ templates (mostly in terms of type safety) but in a more restricted (and therefore potentially less confusing) way.

Q: Why can't I use static and const together?
A: All constants declarations are implicitly static, and the C# specification states that the (redundant) inclusion of the static modifier is prohibited. I believe this is to avoid the confusion which could occur if a reader were to see two constants, one declared static and one not - they could easily assume that the difference in specification implied a difference in semantics. (Having said that, there is no prohibition on redundantly specifying an access modifier which is also the default one, where there is a choice. For instance, a (concrete) method can be explicitly marked as private despite that being the default. The rule appears to be that where there is no choice (e.g. a method declaration in an interface) the redundant modifier is prohibited. Where there is a choice, it's allowed.

DOTNET Framework FAQ Questions

FAQ Questions

What is .NET?
What version of Windows do I need to use .NET?
Do I have to be running Windows to use .NET?
Does the framework have to be installed to run my .NET application?
What do all the acronyms (CLI, CLR, IL etc) mean?
What is Whidbey and when is it coming out?
What versions of .NET are there?
What does 'managed' mean in the .NET context?
Does .NET have any compressiong/zipping capabilities?

FAQ Answers

Q: What is .NET?
A: NET is a platform created by Microsoft. It consists of a virtual execution environment (including garbage collection, JITting, strong versioning, type and memory safety etc) and a large runtime library. It is at the heart of Microsoft's future strategy for the Windows platform, and will be a central part of the next release of Windows (Longhorn).


Q: What version of Windows do I need to use .NET?
A: The .NET framework itself runs on all versions of Windows from Windows 98/NT4 upwards.

It does not run on Windows 95 or NT3.5. For NT4, it requires service pack 6a.

Q: Do I have to be running Windows to use .NET?
A: There are various (mostly open source) projects to write a CLR (Common Language Runtime) on other operating systems such as Linux and BSD. The two best known are:
Mono - an open source multi-platform systemROTOR - a Microsoft Shared Source implementation for FreeBSD, Windows XP and Mac OS X 10.2. (Link is to a website with a range of links; no one link seems particularly suitable on its own.)Strictly speaking, these are not actually .NET - .NET is Microsoft's closed-source Windows-only implementation of the CLR and other technologies, including various other framework libraries which aren't all covered in the above projects (which may themselves have libraries which aren't in .NET-proper). They do, however, allow you to write programs in C# and run them.

Q: Does the framework have to be installed to run my .NET application?
A: Yes - if you have a managed application, it will require the framework to be present in order to run. This is like requiring the Win32 libraries to be present in order to run Windows applications. Pre-compiling your code using ngen doesn't affect this requirement.Having said the above, there are two products which build everything you need from the framework for your application, along with your application itself, into one big bundle:
RemoteSoft's linker and mini-deployment tool Thinstall Studio Both of these mean the framework itself isn't required, and give additional protection against decompilation. The downside is that if a user then has many such applications, they end up effectively with multiple copies of bits of the framework. I cannot vouch for either of these products myself, as I've had no experience of them.

Q: What do all the acronyms (CLI, CLR, IL etc) mean?
A: CIL - Common Intermediate LanguageThe language all .NET languages compile to. Equivalent to Java bytecode.CLI - Common Language InfrastructureThe combination of the CLR, CLS, CTS and CILCLR - Common Language RuntimeThe runtime environment itself, including garbage collection, threading etc.CLS - Common Language SpecificationA set of conventions intended to promote language interoperability.CTS - Common Type SystemThe language-neutral type system used in the CLI.IL - Intermediate LanguageMore commonly used abbreviation for CIL.VES - Virtual Execution SystemAnother name for the CLR as far as I can tell.


Q: What is Whidbey and when is it coming out?
A: Whidbey is the next version of Visual Studio .NET, and is closely tied to V2.0 of the framework. It is likely to be released in the first half of 2005.


Q: What versions of .NET are there?
A: The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time, the final version of Visual Studio.NET was made available to MSDN subscribers..NET 1.1 was released in April 2003 - it's mostly bug fixes for 1.0..NET 2.0 is expected in 2005.


Q: What does 'managed' mean in the .NET context?
A: The term 'managed' is the cause of much confusion. It is used in various places within .NET, meaning slightly different things.Managed code: The .NET framework provides several core run-time services to the programs that run within it - for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. Such code is called managed code.Managed data: This is data that is allocated and freed by the .NET runtime's garbage collector.Managed classes: This is usually referred to in the context of Managed Extensions (ME) for C++. When using ME C++, a class can be marked with the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector, but it also means more than that. The class becomes a fully paid-up member of the .NET community with the benefits and restrictions that brings. An example of a benefit is proper interop with classes written in other languages - for example, a managed C++ class can inherit from a VB class.


Q: Does .NET have any compressiong/zipping capabilities?
A: The .NET framework doesn't contain any general purpose compression libraries, but there are plenty of third-party libraries available. The most commonly referenced is probably
SharpZipLib, which is free and open source but may still be used in commercial applications.

Monday, January 21, 2008

Adding Google sitemap to blogger.com blog account

You can now add Google sitemap to your blogger.com account and increase your chances of being indexed in Google search engine result.
You can add a Sitemap to your account to give Google more information about the pages in your site to help Google crawl them more effectively.
Step # 1: Login to sitemap account
At the top of screen you will see option to add site. Just paste URL of your blog (for example http://cyberciti.blogspot.com/)
(Click to enlarge image)
Click on Ok button. Next you will get confirmation message. Your site has been added to your account.
Step # 2: Now you need to verify your ownership of blog to view detailed statistics. Click on verify link. Google offers two methods of verification. You can either upload an HTML file with a name we specify (which is not possible with Google Blogger account), or you can add a META tag to your site’s index file. Adding META tag via template code is possible so just select Add a META tag from drop down menu:

It will generate code for you, copy the meta tag and paste it into your blogger.com template section).


Step # 3: Go to your blogger.com and login to your account. Goto your blog > Click on TemplatePaste the META tag code after section:
(Click to enlarge image)
Click on Save Template changes button
Click on Republish Index only button > Wait for few seconds so that your blog being published successfully.


Step # 4: Now goto sitemap account and click the box that read as follows:
I’ve added the META tag in the home page of http://cyberciti.blogspot.com/. Click on Verify button.

Step # 5: Now your site is added to sitemap account and verification is done. Next you need to add actual sitemap url. Since blogger.com account donĂ¢€™t allow you to create a text file or anything else you need to add your site feed (ATOM xml) file as a site map. Click on add a sitemap link:

Step # 6: You can add a Sitemap to your account to provide Google additional information about about your blog. Google will process your Sitemap and provide information on any errors in the Sitemaps tab as well your sitemap will be downloaded everyday to index your blog fast.Select type as : Add General Web sitemap
Now you need to add Atom 0.3 feeds. Generally, you would use this format only if your site already has a syndication feed and this is the only way to add sitemap to your blogger.com account.
Paste url of your Atom feed: For example http://cyberciti.blogspot.com/atom.xml and click on Add Web sitemap:
Update: If you are using a new blogger beta system, use http://yourblogname.blogspot.com/feeds/posts/full as a feed url.
(Click to enlarge image)You will get confirmation:You have added a Sitemap to http://cyberciti.blogspot.com/. Reports may take several hours to update. Thank you for your patience!
And you are done and your blog will be now index very fast (depend upon your posting and content).

Saturday, January 5, 2008

ASP.NET Interview questions

1. What is the difference between excute query and excute nonquery.?

Latest Answer: There is no object like ExecuteQuery...



2. ASP.NET Binding

Why do we binds the data in Web-application not in the Windows-application ?

Latest Answer: In asp.net output will be displayed in Browser.Browser understands only html,css,and java scrip...




3. What I should answer person on interview on question “Can User Control be stored in library?&

What I should answer person on interview on question “Can User Control be stored in library?”. The correct answer – Yes, but interviewer demanding that correct answer – No because User controls are not pre-compilable



4. is there any limit for query string? if means what is the maximum size?.

Answer: Just want to confirm, there's a limit on the browser side, and another limit on server side, tru...


5. What are the different types of sessions in ASP.Net? Name them.

Latest Answer: ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session...



6. how to load data from one page to another page in asp.net

Latest Answer: what about viewstate, cache and the good old cookes :)...



7. What methods must be used with the application object to ensure that only one process accross a var
What methods must be used with the application object to ensure that only one process accross a varaible at a time?

(Answers: 1) Read / Answer



8. what events will occur when a page is loaded?

Latest Answer: Please Ignore earliar answer as that is not complete and accicdently i clicked on submitThe Page Loa...



9. What are the uses of Reflection? Viewing Metadata.2.Performing type discovery.3.Late binding to methods and properties (dynamic invocation)4.Creating new types at runtime(Reflection EMIT)

Latest Answer: Reflection is used for the late binding of an object in .Net. By using Reflection one can use ...(Answers: 1) Read / Answer


10. What is the use of AutoWireup in asp.net? In which circumstances we have to use this?

Latest Answer: The AutoWireup attribute is either set as True or False. The attribute allows you to fire the events...

Search