String literals in C#

25 December, 2009 | | 1 comments |

Share |
I'm sure a quick peek at the subject of this blog post might make C# enthusiasts think of a mundane topic with nothing to offer. But contrary to that, it has much more to enlighten you. So just read on ...



Strings in C#



Lets clear some of the dare-bare basics regarding Strings(which we thought we knew) in C# :

Strings are reference types used to contain Unicode text.

C# supports two forms of string literals :

1] Regular string literals

A regular string literal consists of zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as '\t' for the tab character) and hexadecimal and Unicode escape sequences. This is the most general form of String which we all use everyday in our work.

Some examples :

String s;

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

--> s = "This is String";

O/P : This is String

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

--> s = "Hello \t world";

O/P : Hello world

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

--> s = "My name is \"Hardik " + "Shah\"";

O/P : My name is "Hardik Shah"

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

As noticed above the following backslash character constants are used frequently while getting a particular O/P in your required format :

| \n | \t | \v | \b | \f | \\ | \" | \' |

Also if you have a large string than you have to append string parts using the '+' operator.

To win over this situation, we have another type of String literal i.e. Verbatim string literals.



2] Verbatim string literals
A verbatim string literal consists of an '@' character followed by a double-quote character, zero or more characters, and a closing double-quote character. So here we have the added advantage that the characters present between the two double-quotes are rendered the way they are and no white-spaces are truncated. Also a lot more ....

Some examples :

String s;

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


--> s = @"hello world";

O/P : hello world

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

-->
s = @"Division is (a\b)";

O/P : Division is (a\b)

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

--> s = @"append this type " + @"in this way";

O/P : append this type in this way

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

Note : ["] in Verbatim string literal is [""] or [\""]


Applications of verbatim string literals :

1] Include a large paragraph of text without using '+' operator.

2] Multiple lines of HTML code can also be used using this type.


Post a Comment

Product Review : The Google Chrome OS

20 December, 2009 | | 1 comments |

Share |
A very bold and unexpected announcement by Mr. Sundar Pichai, Engineering Director, Google on 7th July, 2009 made headlines in the I.T. industry worldwide and subsequently across all forms of media. That was the announcement of the Google Chrome OS. You can read about it Here and Here. The OS is set to release in the second half of 2010 initially for Netbooks but the buzz currently is so high that you see every Tom and Jerry coming with his version of the story. But indeed, the topic is so very intuitive and exciting. Developing an open-source and freeware OS which boots in seconds and delivers rich surfing experience with the Google Chrome browser at the heart of the OS is surely worth an applause. Add to it, Google also offers other valuable web services spanning across E-mail, online storage, ads, custom search, socializing, feeds, source codes, etc.

Guess what, whenever the offering is free unlike Microsoft's offerings, people forget the skepticism and the anticipation is great. And it's true in this case as well, even before the working ALPHA of Google Chrome OS hits the tester's basket rumors of Google having talks with H/W vendors like Dell, Acer, HP, etc regarding support of its OS to launching its own version of its Netbook bearing its OS just refuse to die. Google just released its source code developed till date on its Chrome OS and a couple of enthusiasts were quick to compile it and get a VM(Virtual Machine) image out of it. It also happened very quickly that a friend of mine passed this very precious stuff to me and I was prompt to try and put a review on it, though it took a lot of annoying time to get things to work. So before I start with the review I think reading a bit to clear some fallacies about Chromium projects, Chromium, Chromium OS and the Google Chrome OS would help. Perhaps this link Here will suffice.




So here I go with my very first review of Google Chrome OS :

  • The built is that of Linux on GNOME environment(written in Gtk+) with source code procured by Google from the open-source community under the GNU and GPL.
  • The OS currently boots with the presumption that you have an active Internet connection and you are kind of an user who spends a major part of his time over the Internet.
  • The OS boots up with the login screen which takes your Google Account and password to begin. When done the browser shows up, which cannot be escaped and it logs you straight into your Inbox(if you have one).


Google Chrome OS

Google Chrome OS

Google Chrome OS
  • The browser works in a Sandbox architecture which is a core part of the OS to enforce a strict security regime. So no OS level or desktop applications tolerated like in Windows !!! But the browser comes equipped with all basic features like bookmarking, download manager, incognito mode, crashed tabs recovery, proxy settings, etc.
  • The browser has a special tab on top-left for access to all valuable web services like Google Apps, Gmail, Twitter, Facebook, Youtube, etc and others if needed can be added to the list. So needs like working over Office documents, mails, viewing video, social networking are easily sufficed.
  • The user doesn't have access to the system files explicitly but he can save and access any files there if he wants from the browser.
  • The browser can also bear a Theme from many possible sources.
  • So eventually, it's the browser which becomes the cynosure.


Google Chrome OS


Google Chrome OS


Google Chrome OS

Google Chrome OS

Google Chrome OS

Google Chrome OS

Google Chrome OS



SHOCKING TRAUMA !!!

  • What was really surprising when I checked the additional configuration options deep down in the browser was that the OS keeps room for the user to install other browsers like Firefox, Opera, etc and you can even set them to default.

Google Chrome OS
  • The second piece of surprise was that the Google Chrome browser offers a choice on the default search provider. Yes, it's true !!! You have a choice of Google, Yahoo! and Bing at the moment.


Google Chrome OS
Well if the above two surprises does survive to find its place at the FINAL than all fingers up for Google for developing an unbiased and altruistic piece of software for the user community.



Post a Comment

A Guide to SQL Server Management Studio 2005

19 December, 2009 | | 0 comments |

Share |
Like a lot of my friends and followers knew from my Twitter and Facebook updates, I had enrolled for a Seven Saturday series on System Administration courtesy - MumbaiIT Pro. The series which has its final session today saw some of the most prominent professionals from India's I.T. industry leaving their footprint in the minds of the audience with their enlivening and comprehensive coverage on the topics of their strength. The audience on the other hand were also enthralled and kept alive with contests and other Q & A sessions. Such a huge party in town and how can I stay behind? Having said this I had my intuition going strong before the start of this programme and hence I decided to volunteer in it with contributions in the form of Twitter updates and technical write-ups inspite of my jobbing blues and busy schedules.

The right time and the topic came and I decided to write in brief on SQL Server 2005 which I guess was a topic of my strength since I've been developing on ASP.Net using Visual Studio 2008 IDE and SQL Server 2005 Express as my back-end. So here I sat using all Office and web tools to get a writeup done but the climax turned out to be much more interesting - I just went on & on and ended up making a guide on the topic which now even included SQL Server Management Studio 2005 and a lot many sub-topics below it. A special thanks to Mark O'Neill - Managing Director of MakeUseOf whose "A Complete Guide to Twitter" was a very good source of inspiration to me and I emulated it quite well using Microsoft Office Word 2007. What ensued was that I have even applied for the post of a Writer on their portal.




Table of Contents in the Guide

1] Introduction

• What is SQL Server 2005 ?
• Anatomy of Database files
• Types of databases in SQL Server 2005
• A quick overview of the SQL Server Management Studio 2005 Wizard
• How to Login ?
• How to create a database using the Wizard ?
• How to execute a query ?
• Using diagnostic SQL Queries

2] Backup and Recovery

• Types of Backup
• Anatomy of Backup files
• How to take a backup ?
• How to restore from a backup ?

3] Security

• Creating Logins




You can download the Guide : Here




Transparency and Hover effects using CSS

04 December, 2009 | | 0 comments |

Share |
We all have witnessed the transparent and hover effects on websites. The very common approach which web designers and developers follow is that they make the object [transparent] when a mouse hovers above it. This transparency varies depending upon the canvas/button/image upon which the effect is to be applied. Myriad of Javascript codes are available over the web to apply these effects but it's even much simple to understand the concept behind it and use it by yourself. All you need is a few basics of CSS & HTML and that's it you're done !!!



Problem Definition : Apply transparent effect to an Image when mouse hovers above it.

Theoretical Approach : Under normal situation the transparency is absolute i.e. 1.0 (For Others) and 100 (For IE). When the mouse hovers above the image it should set the transparency to 0.4 (for Others) and 40 (For IE).


Transparency effects using CSS

Practical Approach : Define two CSS classes which do the above i.e one for applying the transparency and the other for setting it to normal. The event handlers for [onmouseover] and [onmouseout] can be handled by inline Javascript.

CODE Snippet :

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>** Transparency Effect Example **</title>

  5. <style type="text/css">
  6. .fadein
  7. {
  8. filter:alpha(opacity=40);
  9. opacity:0.4;
  10. }

  11. .fadeout
  12. {
  13. filter:alpha(opacity=100);
  14. opacity:1.0;
  15. }
  16. </style>

  17. </head>
  18. <body>

  19. <img src="Search.gif" alt="Search Image" onmouseover="this.className='fadein'" onmouseout="this.className='fadeout'" />

  20. </body>
  21. </html>


Note :
  • Internet Explorer takes the 'filter' property as mentioned in the CSS class to render the transparency. Rest all browsers accept the 'opacity' property.
  • Maintain the order of the property as mentioned in the CSS class. Interchanging it will result in the effect ceasing to work in IE.
  • Avoid using double quotes ["] for the properties in CSS as it malfunctions in IE.



More HOVER effects using CSS pseudo-classes : Here



Post a Comment

Different ways of accessing a CSS class

03 December, 2009 | | 0 comments |

Share |
CSS(Cascading Style Sheets) in an asset to our web. Apart from being ubiquitous it's also indispensable for enterprise level web projects. No surprises, web designers and developers find themselves facing questions on it when they appear for an interview. Yeah, it's that important !!! If you've still not seen what CSS does then you go [Here]. Quite frankly, CSS 2.0 has evolved very well with a lot of new properties added to it along with new concepts like Pseudo classes, etc. A majority of 21st generation browsers like IE 7, Firefox 2.0, Chrome 2.0(stable), Safari, Opera 8.0 and above have inherent support of CSS 2.0 and some even support v2.1. The only exception to the rule is IE 6 which I don't believe stands in the league but if you still feel otherwise then you seriously need a dose of Mozilla Firefox !!!

I've seen numerous examples of internal and external CSS being explained over forums and across many websites but rarely does any of them explain the different ways by which you can access a CSS class. So I'll explain it here...



Option 1 : You can define a class named after the type of the HTML [container] element

Result : The style will be applied to all the elements of the same type

Example : The DIV and SPAN tags

CODE Snippet :

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <style type="text/css">
  5. span
  6. {
  7. font-family: Calibri;
  8. background: Aqua;
  9. text-align: center;
  10. }
  11. </style>
  12. </head>

  13. <body>

  14. <span>Example 1</span>

  15. <br />

  16. <span>All SPAN tags will have the same attributes</span>

  17. </body>
  18. </html>




Option 2 : You can define a class using an identifier prefixed with a '.' operator. Do not include spaces in the identifier and keep it unique. You can then access it using the 'class' attribute of the element to whom you want to apply this style to.

Result : The style will be applied only to those elements which [reference] this identifier

CODE Snippet :

  1. CSS :

  2. .style1
  3. {
  4. background: Aqua;
  5. text-align: center;
  6. }

  7. HTML :

  8. <span class="style1">This is Example 2</span>




Option 3 : You can define a class using an identifier as above but prefix it with a '#' operator. You can then access it using the 'id' attribute of the element to whom you want to apply this style to.

Result : The style will be applied only to those elements which [has] this identifier

CODE Snippet :

  1. CSS :

  2. #style1
  3. {
  4. background: Aqua;
  5. text-align: center;
  6. }

HTML :

  1. <span id="style1">This is Example 2</span>



Now having learnt the above three methods of accessing a CSS class, its time to apply multiple classes at the same time.

Option 4 : You can define multiple classes with unique identifiers as in Example 2 and then apply the classes to the elements in their 'class' attribute seperated by a space.

CODE Snippet :

  1. CSS :

  2. .style1
  3. {
  4. background: Aqua;
  5. text-align: center;
  6. }

  7. .style2
  8. {
  9. font-family:Calibri;
  10. }

HTML :

  1. <span id="style1 style2">This is Example 2</span>