Showing posts with label Visual Basic. Show all posts
Showing posts with label Visual Basic. Show all posts

Tuesday, July 17, 2012

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,Intermediate,VS2010,Articles,Computer Tips and Tricks,Computer Tutorials,Dot Net Interview Questions,Interview Questions,Microsoft,Sample Code,Visual Basic,Visual Studio

Saturday, May 14, 2011

Displaying RowNumber in datagrid control

In this post We will show how we can display row number in datagrid control using IMultiValueConverter.Let us start with the code.The code shown in the List 1 is used to bind using the IMultiValueConverter and the passing parameter for the binding converter are the binding and parent datagrid control

< DataGridTextColumn Header="Row Number" IsReadOnly="True">
< DataGridTextColumn.Binding>
< MultiBinding Converter="{StaticResource rowNumberConverter}">
< Binding />
< Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}" />
< /MultiBinding>
< /DataGridTextColumn.Binding>
< /DataGridTextColumn>

Now in the converter I have simple code to show the row number of the current element which is passed to the converter in first parameter. I have store it in the object type variable. As I don't know what is the type of the first parameter and then I created another parameter of type data grid control and save the second parameter in it. Now in the next statement I have get the Index of the passed parameter in the data grid control and also added 1 in it, as IndexOf will return 0 for the first element. You can see the code in List 2.

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
item = values[0]; 
DataGrid grdPassedGrid = values[1] as DataGrid;
int intRowNumber = grdPassedGrid.Items.IndexOf(item) + 1;
return intRowNumber.ToString().PadLeft(2, '0'); 
And you can see the Row Number column in the Image 1, I have set the header text of the column to "Row Number", You can changed it to you requirements.
In the Image 1 you can see that I have used the left padding for the row number, as you can see that each row number is padded left by 0 I have used it to 2 values, You can also pass the length of your padding in the parameter of the IMultiValueConverter.

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, March 20, 2011

Coding a Default Property

The concept of a "default property" for an object isn't what it used to be. Programmers new to VB.NET after 2001 (When VB6 was taken behind the barn and shot.) may not even be aware of how it used to be. In brief, you used to be able to write code like this:

TextBox1 = "Text"
This was really shorthand for ...

TextBox1.Text = "Text"
... because the Text property was the default property.
VB.NET continues to include a "Default" property attribute, but it's not at all the same. In fact, the way it's really used is documented in such an obscure way at Microsoft that there is a real need for some clarification.
The Microsoft documentation for declaring a Default Property in a Class definition is fairly straightforward. But you have to read the whole thing. The initial step-by-step instructions don't work. You could get the idea that all you have to do is simply use the Default keyword instead of Private, Public, or Shared.

Default Property myProperty(ByVal index As Integer) As String
There are a few more rules.
  1. The new VB 2010 "auto implemented" property syntax doesn't work. In other words, you also need a Get and Set and an End Property. (But, Microsoft doesn't make this part of their documentation.)
  2. You have to use at least one parameter for the property. (There's more to this rule, too.)
You might think that you can just write this code:

' Code in a calling procedure
Dim theInstance As New aClassExample

Public Class aClassExample
Private m_myProperty As String = "Red"
Default Property myProperty(
ByVal theDefaultArg As Integer
) As String
myProperty = m_myProperty
End Get
Set(ByVal value As String)
m_myProperty = value
End Set
End Property
End Class
No. An ArgumentException is thrown. It's fairly obvious to see that an argument must be passed, but the language of the exception message is curious:

In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
So, this isn't just a default property, it's also an indexed property. That's something that the documentation doesn't make clear. The code that does work simply adds the parameter to the instance in the calling procedure:

What does the "1" parameter do in this code? Absolutely nothing. But it still has to be there. In other words, there is no way to write a default property that is not indexed.
The right way to think of a "default" property in VB.NET is to substitute the word "indexed" for "default". In VB.NET, you can create a property that makes it simpler to define indexes to a collection. Microsoft just used the keyword "Default" for this type of property. Many sources, in fact, refer to a VB.NET default property as an indexer because that's what it does.
Here's an example that does it right. This code declares an indexer in the class DefaultPropClass. This indexer is capable of returning a member of an array that is maintained in an instance of the class by either an index number or a string that matches an element of the array.

Public Class DefaultPropClass
Private m_theProperty As List(Of theStructure)
Public Sub New()
m_theProperty = New List(Of theStructure)
End Sub
' This ReadOnly Property returns the
' value corresponding to an integer index
Default Property theProperty(
ByVal index As Integer) As theStructure
Return m_theProperty(index)
End Get
Set(ByVal value As theStructure)
End Set
End Property
' This ReadOnly Property returns the
' value corresponding to a string key
Default ReadOnly Property theProperty(
ByVal index As String) As theStructure
For Each p As theStructure
In m_theProperty
If p.theKey = index Then
Return p
End If
Return Nothing
End Get
End Property
End Class
Public Structure theStructure
Dim theKey As String
Dim theValue As String
End Structure
The code that uses this class might look like this:

Dim aCollection As New theStructure
aCollection.theKey = "1"
aCollection.theValue = "George"
Dim aInstance As New DefaultPropClass
aInstance(1) = aCollection
aCollection.theKey = "2"
aCollection.theValue = "Jeremy"
aInstance(2) = aCollection
MsgBox("Integer parameter 1: " &
MsgBox("String parameter 1: " &
The value returned by the integer parameter 1 is "Jeremy" since the collection is zero based. the value returned by the string parameter "1" is "George". You might be asking, "Where is anything defaulted?" One way to answer the question is to note that this code also works:

MsgBox("String parameter 1: " &
In other words, by using a default property you can avoid typing the text ".theProperty" in your code. It doesn't seem worth it. This might help explain why Microsoft has made upgrading their documentation on this a (a-hem) secondary priority. In fact, at the very end of one Microsoft page, they're pretty blunt about it:

You should consider not defining default properties. For code readability, you should also consider always referring to all properties explicitly, even default properties.