Showing posts with label Sample Code. Show all posts
Showing posts with label Sample Code. Show all posts

Monday, August 27, 2012

A Beginner's Tutorial on String Comparison in C#

Usually in our applications when we want to compare two strings we use the equality operator. Under most scenarios this will work properly but still we should know what are the other ways we can do string comparisons and perhaps achieve better performance and results. So lets say I have a variable str and I want to check whether its value is equal to "Yes" or not.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

C#,.NET,Architect,Intermediate,Computer Tips and Tricks,Computer Tutorials,Dot Net Interview Questions,Interview Questions,Programming Tutorials,Sample Code,String,Beginner

Step by Step Creating UserControl : DataGridView With Paging

I have Created this UserControl for those who are looking for DataGridView paging functionality. So many times we are using DataGridView in our Windows application with paging. So my intention for this article is to show User Control creation and To provide DataGridView with paging functionality.

Although Creating paging functionality is very basic. but i want to show you features of UserControls through this article and i think this would be the best topic to learn user control. People already know about DataGridView and Paging so there won't be any additional knowledge required to understand the functionality.

Read More....

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

C#,.NET,Architect,Intermediate,Computer Tutorials,Programming Tutorials,Sample Code,SilverLight,SilverLight Tutorial,WPF,LINQ,XAML,C# 4.0

Tuesday, July 17, 2012

Positioning Popup Menus in Windows 8 Metro

Often when building Windows 8 apps you'll want to provide a menu of options from the app bar, this may be a list of different ways to sort or filter the data. For these simple menus WinRT provides the PopupMenu control (for more complicated popup user interfaces I recommend the Flyout control from the Callisto library), these menus are very easy to create by creating UI Commands and appending them to the menus Commands collection.

Read More from: Original Source

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

C#,.NET,Intermediate,Advanced,VS2010,Articles,Computer Tips and Tricks,Computer Tutorials,Metro Style Applications,Microsoft,Operating Systems,Programming Tutorials,Sample Code,Visual Studio,Window,Windows 8

Return Multiple Values(or Objects) in VB.NET

You might have searched "How to return multiple objects in VB.Net" in google and you might have got a lot of Ir-relevant articles. But this is not such an article, this goes to the point. I am going to teach you how to return multiple values in

I gave a lot of try (Searching), how to do the stuff but most of the search results turned out to be like using a single object and returning multiple values in it, but that I do not need. So I thought of writing an article here about the same. So at least it will be helpful for sum beginners.

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

.NET,Architect,Intermediate,VS2010,Articles,ASP.Net,ASP.Net Tutorials,Computer Tips and Tricks,Computer Tutorials,Dot Net Interview Questions,Interview Questions,Microsoft,Sample Code,SilverLight,SilverLight Tutorial,Visual Basic,Visual Studio

Saturday, May 14, 2011

Purpose and use of interfaces

This Article explains the Purpose and use of interfaces. We can learn when and where we need to use interfaces and how it helps us in Object oriented programming.


Interface is basically a class which will have empty method(s), delegate(s) or event(s). The implementation of the methods is done in the class that implements the interface, that is the reason the interface's method will not have definition.

Interface will be defined using the keyword interface. Interfaces would be used as a intermediater in most of the software program.


Interface is used for the below purposes:
  1. To maintain the Standardization or uniformity in the method definition
  2. It enables to implement Decoupling.


It is very much possible that multiple developers write code for common operations and they will use their own naming convention for their methods. In order to maintain the uniformity in the code, we can use interfaces. The Senior developer or architect can design the interfaces with common method names, that can be used by mulitple developers. So the developers cann't use their naming conventions for the method. It brings the more readablity too.


Decoupling is very important in software architecture design. The system is said to be good system, when one process doesn't impact the other.So, The interface helps us to seperate one process from impacting other and the future implementation should not affect the currect process. Basically our system should be expandable with out impact.

Let us look at the first purpose : Standardaization

namespace InterfaceExample
    interface IDboperation 
        public void insertData();
    public class Dbwork
        public void updatetoDb();

    public class Dbtask
        public void insertdb()


In the Above example, there are two classes written by two different developers [Class Dbwork and Class Dbtask which as two different function. One developer named it as updatetoDb and another developer named it as insertdb. Instead, if we insist developers to implement the interface, they will use the common function called insertdata(); That way we bring uniformity and standard in our development.

Purpose of Decoupling:

namespace InterfaceExample
    interface ICommoanOperations
        void IExportData();
    public class ExporttoPdf :ICommoanOperations
        public void ExportDataToPdf
        //Code to Read data and export to Pdf

    public class ExporttoExcel :ICommoanOperations
        public void ExportDatatoExcel
         //Code to Read data and export to Excel

    public class Client
        public void Export(ICommoanOperations InterfaceObj)

In the above example, there are two classes , one for exporting data to pdf and other for excel. Now the interface acts as a intermediater between two classes. Instead of calling the direct concrete class methods, we can call interface that calls the respective class method. This enables decoupling in our program. More over, if tomorrow , we need another fuctionality , we can attach easily.


It is good practice to develop code using Interfaces. And that is the reason, we implement WCF Services using Interfaces.

Reading Harddisk Information Using Silverlight 4 Out Of Browser Application

To read the hard disk information in silverlight was my question which I have search on net and was keen to do that, because I want to learn the silverlight. So after search on internet and searching the msdn for this question here is what I have found. You can see the out of the sample code in the Image 1, Here in the Image 1 I have display the hard disk partition just like the window 7 , the title , the progress bar to indicate the usage of the partition space and the at the end the summary of the the partition size.
Image 1
Now let us start with the code sample. First you have to create silverlight out of browser application for this you can click here to read how to create an out of browser application. From the link you can learn how to create an out of browser application in detail.Below is my code which is used to get the drive information. Here you can see that I have called the AutomationFactory.CreateObject, and passing the progID to the CreateObject.The AutomationFactory Provides access to registered Automation servers.Automation is a Windows-based technology that applications use to expose functionality to scripting tools and other applications. For example, you can use Automation to add Office features to your Silverlight-based applications.
An application or component exposing functionality is called an Automation server; an application accessing the functionality is called an Automation client. Because Automation servers must be preinstalled and run in full trust, Silverlight enables only trusted applications to serve as Automation clients.
dynamic fileSystem = AutomationFactory.CreateObject("Scripting.FileSystemObject");
dynamic drives = fileSystem.Drives;
DriveInformationCollection = new List≶DriveInformation>();

foreach (var drive in drives)
if (drive.IsReady)
DriveInformationCollection.Add(new DriveInformation
VolumeName = drive.VolumeName,
DriveLetter = drive.DriveLetter,
TotalSpace = drive.TotalSize,
FreeSpace = drive.FreeSpace,
FileSystem = drive.FileSystem,
DriveType = (eDriveType)Enum.ToObject(typeof(eDriveType), drive.DriveType)
catch (COMException Ex)
string strMessage = Ex.Message;
Now we have the reference of the automation server which is store in fileSystem of type dynamic.Dynamic is a new type provided by framework 4, you can get more information about the dynamic type by clicking here. Next I have call the drives object of the fileSystem to store the drive in new dynamic object. And then I have used to foreach loop to get the drive information to be store in the class which I have created with the name DriveInformation name.The Drive object allows you to gain information about the various drives attached to a system, either physically or over a network. Its properties allow you to obtain information about:
  • The total size of the drive in bytes (TotalSize property)
  • How much space is available on the drive in bytes (AvailableSpace or FreeSpace properties)
  • What letter is assigned to the drive (DriveLetter property)
  • What type of drive it is, such as removable, fixed, network, CD-ROM, or RAM disk (DriveType property)
  • The drive's serial number (SerialNumber property)
  • The type of file system the drive uses, such as FAT, FAT32, NTFS, and so forth (FileSystem property)
  • Whether a drive is available for use (IsReady property)
  • The name of the share and/or volume (ShareName and VolumeName properties)
  • The path or root folder of the drive (Path and RootFolder properties)
In the view of the form. I have used the list box control to display the drive information , which consist of the text block and the progress bar control.For progress bar control I have added two ChangePropertyAction. The condition for first ChangePropertyAction is to check the value of the progress bar if the value is greater then or equal to 80 then the progress bar will be shown red and if the value of the progress bar is less then 80 then progress bar will be shown normally. And the bottom of the user control I have used the grid layout control, the data context of the grid control is set to the selected Item of the list box control. When the selection of the list box changed the correspondent detail of the selected item will be displayed at the bottom of the user control.


1- Automation Class

2- Working with Drives and Folders

Changing Background Color Of DataGrid Cell WPF 4

In this short post I will show you how to change the background color of the column of the data grid control depending on the binding value.Let us start with the code what code or technique you need to change the background color of the column of the data grid control.The output of the example code can be see in Image 1. Here you can see that I have set background of the column to green and red which has values 80 and 90 respectively. Now I will explain you the code which is used to set the background of the column.
In the List 1 you can see the xaml code which is used to set the background color of the column of the data grid control, depending on the value of the binding property.Here you can see that I have used the DataGridTemplateColumn and set the header and the sortMemberPath ( used to sort the column, if not given you can't sort the DataGridTemplateColumn). And then I have used the CellTemplate to define the DataTemplate of the column. As I have only one property to be bind in this column so I have place border control and then inside the border control I have place the text block control and bind the text property of the text block control.
 <DataGridTemplateColumn Header="Total Sale in %" SortMemberPath="Sales">
<DataTemplate >
<Border x:Name="brdBroder" VerticalAlignment="Stretch" Margin="1">
<TextBlock Text="{Binding Sales}" Margin="3,1" x:Name="txtTextBlock"/>
<DataTrigger Binding="{Binding Sales}" Value="80">
<Setter TargetName="brdBroder" Property="Background" Value="Green"/>
<Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>
<DataTrigger Binding="{Binding Sales}" Value="90">
<Setter TargetName="brdBroder" Property="Background" Value="Red"/>
<Setter TargetName="txtTextBlock" Property="Foreground" Value="White"/>

Next is to define the trigger which are used to change the background color of the border which is placed in the Data Template. Here I have used the DataTrigger, which will used to check the value of 80 and 90 and set the background color of the border control to the green and red respectively as you can see in the Image 1 which is shown at the start of the post

Saturday, April 9, 2011

New Interview Questions for Senior Software Engineers

New Interview Questions for Senior Software Engineers
  • What is something substantive that you've done to improve as a developer in your career?
  • Would you call yourself a craftsman (craftsperson) and what does that word mean to you?
  • Implement a using on .
  • What is SOLID?
  • Why is the Single Responsibility Principle important?
  • What is Inversion of Control? How does that relate to dependency injection?
  • How does a 3 tier application differ from a 2 tier one?
  • Why are interfaces important?
  • What is the Repository pattern? The Factory Pattern? Why are patterns important?
  • What are some examples of anti-patterns?
  • Who are the Gang of Four? Why should you care?
  • How do the MVP, MVC, and MVVM patterns relate? When are they appropriate?
  • Explain the concept of Separation of Concerns and it's pros and cons.
  • Name three primary attributes of object-oriented design. Describe what they mean and why they're important.
  • Describe a pattern that is NOT the Factory Pattern? How is it used and when?
  • You have just been put in charge of a legacy code project with maintainability problems. What kind of things would you look to improve to get the project on a stable footing?
  • Show me a portfolio of all the applications you worked on, and tell me how you contributed to design them.
  • What are some alternate ways to store data other than a relational database? Why would you do that, and what are the trade-offs?
  • Explain the concept of convention over configuration, and talk about an example of convention over configuration you have seen in the wild.
  • Explain the differences between stateless and stateful systems, and impacts of state on parallelism.
  • Discuss the differences between Mocks and Stubs/Fakes and where you might use them (answers aren't that important here, just the discussion that would ensue).
  • Discuss the concept of YAGNI and explain something you did recently that adhered to this practice.
  • Explain what is meant by a sandbox, why you would use one, and identify examples of sandboxes in the wild.
  • Concurrency
    • What's the difference between Locking and Lockless (Optimistic and Pessimistic) concurrency models?
    • What kinds of problems can you hit with locking model? And a lockless model?
    • What trade offs do you have for resource contention?
    • How might a task-based model differ from a threaded model?
    • What's the difference between asynchrony and concurrency?
  • Are you still writing code? Do you love it?
  • You've just been assigned to a project in a new technology how would you get started?
  • How does the addition of Service Orientation change systems? When is it appropriate to use?
  • What do you do to stay abreast of the latest technologies and tools?
  • What is the difference between "set" logic, and "procedural" logic. When would you use each one and why?
  • What Source Control systems have you worked with?
  • What is Continuous Integration?  Have you used it and why is it important?
  • Describe a software development life cycle that you've managed.
  • How do you react to people criticizing your code/documents?
  • Whose blogs or podcasts do you follow? Do you blog or podcast?
  • Tell me about some of your hobby projects that you've written in your off time.
  • What is the last programming book you read?
  • Describe, in as much detail as you think is relevant, as deeply as you can, what happens when I type "" into a browser and press "Go".
  • Describe the structure and contents of a design document, or a set of design documents, for a multi-tiered web application.
  • What's so great about ?
  • How can you stop your DBA from making off with a list of your users’ passwords?
  • What do you do when you get stuck with a problem you can't solve?
  • If your database was under a lot of strain, what are the first few things you might consider to speed it up?
  • What is SQL injection?
  • What's the difference between unit test and integration test?
  • Tell me about 3 times you failed.
  • What is Refactoring ? Have you used it and it is important? Name three common refactorings.
  • You have two computers, and you want to get data from one to the other. How could you do it?
  • Left to your own devices, what would you create?
  • Given Time, Cost, Client satisfaction and Best Practices, how will you prioritize them for a project you are working on? Explain why.
  • What's the difference between a web server, web farm and web garden? How would your web application need to change for each?
  • What value do daily builds, automated testing, and peer reviews add to a project? What disadvantages are there?
  • What elements of OO design are most prone to abuse? How would you mitigate that?
  • When do you know your code is ready for production?
  • What's YAGNI? Is this list of questions an example?
  • Describe to me some bad code you've read or inherited lately.
Your thoughts? I'll add good questions from the comments throughout the day.

Sunday, February 13, 2011

iPhone FBConnect: Facebook Connect Tutorial

Now a days social networking websites like facebook are becoming very popular, so integrating facebook with app has become a necessity to make you application popular. We are going to do the same through this tutorial. The Facebook Connect SDK provides code which third-party developers can embed into their applications to connect to their Facebook accounts and exchange information with iPhone apps. It’s a way of embedding “social context” to an iPhone app, according to Facebook.
Create a Viewbased Application with name ‘FacebookAPI’.
1.Download Facebook Connect for iPhone SDK (
Just go through the project. In particular, the “Connect” sample project. Sample Project gives demo of some of the functionality.
1.1.Open src/FBConnect.xcodeproj from SDK that you downloaded, and your own project as well.
1.2.Drag n drop FBConnect group. Make sure “Copy items into destination group folder” is NOT checked. It should look as shown below

1.3.Go to Project Menu ->Edit project settings and scroll down to “User Header Search Path” add entry which will point to “src folder”
1.4.To test import all .m n .h files in case any miss. And compile.
2.Login to Facebook. After that go to Developers Page ( as shown below.
3.Register your application with Facebook
3.1.Click on Set up New Application Button in the upper right hand corner.
3.2.Give Application name and click on create application button. Then you will see new application screen with detail including “API key”and “API Secret Key”
Note : This application will not work until you provide your Facebook application’s API keys.
Now to get started with actual coding:
Append Following code in


02#import "FBConnect/FBConnect.h"
03#import "FBConnect/FBSession.h"
05@class FacebookAPIViewController;
07@interface FacebookAPIAppDelegate : NSObject  {
08          UIWindow *window;
09          FacebookAPIViewController *viewController;
10          FBSession *_session;
13@property (nonatomic, retain) IBOutlet UIWindow *window;
14@property (nonatomic, retain) IBOutlet
15                           FacebookAPIViewController *viewController;
16@property (nonatomic,retain) FBSession *_session;
Append Following code in FacebookAPIAppDelegate.m

01#import "FacebookAPIAppDelegate.h"
02#import "FacebookAPIViewController.h"
04@implementation FacebookAPIAppDelegate
06@synthesize window;
07@synthesize viewController;
08@synthesize _session;
10- (void)applicationDidFinishLaunching:(UIApplication *)application {
12// Override point for customization after app launch
13[window addSubview:viewController.view];
14[window makeKeyAndVisible];
17- (void)dealloc {
18          [_session release];
19          [viewController release];
20          [window release];
21          [super dealloc];
Here in FacebookAPIAppDelegate we have just declared _session variable of type FBSession to keep track of the session and to check if session for current user exists or not.
Append Following code in FacebookAPIViewController.h

03#import "FBConnect/FBConnect.h"
04#import "FBConnect/FBSession.h"
06@interface FacebookAPIViewController : UIViewController   {
07             FBLoginButton *loginButton;
08             UIAlertView *facebookAlert;
09             FBSession *usersession;
10             NSString *username;
11             BOOL post;
14@property(nonatomic,retain) FBLoginButton *loginButton;
15@property(nonatomic,retain) UIAlertView *facebookAlert;
16@property(nonatomic,retain)  FBSession *usersession;
17@property(nonatomic,retain) NSString *username;
18@property(nonatomic,assign) BOOL post;
20- (BOOL)textFieldShouldReturn:(UITextField *)textField;
Append Following code in FacebookAPIViewController.m

01#import "FacebookAPIViewController.h"
02#import "FacebookAPIAppDelegate.h"
04#define _APP_KEY @"Your API Key Goes here"
05#define _SECRET_KEY @"Your Secrete Key Goes here"
07@implementation FacebookAPIViewController
08@synthesize loginButton;
09@synthesize facebookAlert;
10@synthesize usersession;
11@synthesize username;
12@synthesize post;
14- (void)viewDidLoad {
15               FacebookAPIAppDelegate *appDelegate =
16                          (FacebookAPIAppDelegate *)   [[UIApplication
17                                            sharedApplication]delegate];
18                if (appDelegate._session == nil){
19                appDelegate._session = [FBSession
20                                   sessionForApplication:_APP_KEY
21                                   secret:_SECRET_KEY delegate:self];
22                 }
23                 if(self.loginButton == NULL)
24                 self.loginButton = [[[FBLoginButton alloc] init] autorelease];
25                 loginButton.frame = CGRectMake(0, 0, 100, 50);
26                 [self.view addSubview:loginButton];
28                 [super viewDidLoad];
31- (void)dealloc {
32               [username release];
33               [usersession release];
34               [loginButton release];
35               [super dealloc];
38- (void)session:(FBSession*)session didLogin:(FBUID)uid {
39                self.usersession =session;
40                NSLog(@"User with id %lld logged in.", uid);
41                [self getFacebookName];
44- (void)getFacebookName {
45         NSString* fql = [NSString stringWithFormat:
46         @"select uid,name from user where uid == %lld",
47                               self.usersession.uid];
48        NSDictionary* params =
49        [NSDictionary dictionaryWithObject:fql
50        forKey:@"query"];
51   [[FBRequest requestWithDelegate:self]
52  call:@"facebook.fql.query" params:params];
56- (void)request:(FBRequest*)request didLoad:(id)result {
57              if ([request.method isEqualToString:@"facebook.fql.query"]) {
58                          NSArray* users = result;
59                          NSDictionary* user = [users objectAtIndex:0];
60                          NSString* name = [user objectForKey:@"name"];
61                          self.username = name;
63                          if ( {
64                                     [self postToWall];
65                            = NO;
66                          }
67              }
70- (void)postToWall {
72               FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
73                                             autorelease];
74               dialog.userMessagePrompt = @"Enter your message:";
75               dialog.attachment = [NSString
76                    stringWithFormat:@"{\"name\":\"Facebook Connect for
77                    iPhone\",\"href\":\"
78                    connect.phptab=iphone\",\"caption\":\"Caption\",
79                    \"description\":\"Description\",\"media\":[{\"type\":
80                    \"image\",\"src\":\"
81                     5914/iphoneconnectbtn.jpg\",\"href\":
82                     \"
83                      tab=iphone/\"}],\"properties\":{\"another link\":
84                      {\"text\":\"Facebook home page\",\"href\":
85                      \"\"}}}"];
87               [dialog show];
91- (BOOL)textFieldShouldReturn:(UITextField *)textField
93                [textField resignFirstResponder];
94                return YES;
Define API key and Secret key with the keys you received while registering your app on facebook.

1#define _APP_KEY @"43e37a535cc09c2013bd76fde78dfcc7"
2#define _SECRET_KEY @"cc14801521a0c4d1dc31b7cacb891072"
Validate session variable in ViewDidLoad. If it doesn’t exist then create the same for using API key and Secret key. For that, one needs to conform the protocol FBSessionDelegate in respective header file. Also create a login button using FBLoginButton.
While implementing protocol FBSessionDelegate one needs to implement following mandatory method

1(void)session:(FBSession*)session didLogin:(FBUID)uid
This methos is automatically called when user is logged in using FBConnect SDK.
In this method we get session for that user and it’s uid which unique identifier for that user.
Once FBSession session is avaiable, we can accesss all the APIs provided by Facebook.
For now, we will see how to post user name and status on the facebook wall.
To get Facebook username a request is send in which select query is written to get username using uid.

1NSString* fql = [NSString stringWithFormat:
2@"select uid,name from user where uid == %lld", self.usersession.uid];
3NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
4[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
Override following FBRequestDelegate method to check the reponse of above query.

1(void)request:(FBRequest*)request didLoad:(id)result
The argument result is an array of NSDictionary Objects which contains info for that user as key-value pairs. Retrieve it as follows:

1NSArray* users = result;
2NSDictionary* user = [users objectAtIndex:0];
3NSString* name = [user objectForKey:@"name"];
Use FBStreamDialog class post message on the facbook wall. A dialog pops up with a message box to post on Wall.

1FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
2dialog.userMessagePrompt = @"Enter your message:";
3dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"\",\"href\":\"\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"\"}}}"];
4[dialog show];
Now Save project (Command +S). Build and Run Project.
Simulator will look like as follows

Click on Fconnect Button and Facebook Login Dialog will appear.

Login with your user name and Password . Wait for untill post to Wall Dialog pops up

You can download the source code from here