CoDebate

Debating Code - [ASP.NET, C#, Sql Server, VB.NET]

Wednesday, March 28, 2018

C# - 'yield' keyword (Kenneth Truyers)

There are so many least-used facilities are still out there within C#. 'Yield' keyword is one such thing!

When searched for learning, I have been getting a lot of examples however most of the examples use 'static' keyword too! Feeling static as irrelevant in this case, I was looking for examples without it.

Later, I came across a wonderful article and would like the readers to go-through it : Kenneth-Truyers - 'yield' keyword!. Thanks to Kenneth (Microsoft MVP) for throwing a good light on this topic!

A gist from his article : (Courtesy : Kenneth Truyers)

  • Yield retains the state of the iteration. (without having to use static keyword or additional collections)
  • Yield returns a placeholder of list (IEnumerable) to the client promising that it would give list of elements on-demand.
  • Yield gives the ability to defer execution. This is evident from his second example.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Thanks for visiting! Happy Programming :)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

posted by Karthikeyan @ 2:39 AM 0 Comments

Sunday, December 13, 2009

Code Challenges (SQL Server)

Challenges are really great in the sense of personal and professional improvement.

BeyondRelational - one kind of raising and solving Challenges for Microsoft Sql Server Developers.

Please check this in here..
http://beyondrelational.com/blogs/tc/default.aspx

What they do actually ?
Well, they raise a problem which should be solved by a SQL Server queries.
Of those Challenges, which might have many other rules and conditions, the main rule might be - to write a single query for complex problems.

Happy Challenging !!!

Labels: , ,

posted by Karthikeyan @ 3:12 AM 0 Comments

Saturday, October 24, 2009

Importing MS Project Plan (.mpp) Data in ASP.NET

If you are struggling with Native libraries to import mpp (MSProject Plan) file data, this article is for you. This is written after my personal experience.

In the beginning , I used MSProject (InterOp) assemblies and a demo version of MSProject for my development. The problem I faced is the license. Like my other Office Automation Efforts(not recommended by MS because of its inconsistency), this assembly demands a MS Project Installation and a license in my machine.

So, I was placed in a chance to search of alternative methods. I got MPXJ, a Java-based Free Open Source library which has extensive collections of methods and utilities in it to read enough an mpp data. This pack also comes with JVM library as it needs for its compilation.

Functions,shown below, are the some of the useful things and will return a List object.
task.getResourceNames()
resource.getTaskAssignments()
resourceassignment.getPeakUnits()

Download MPXJ: http://mpxj.sourceforge.net/

Happy Programming !!!

Labels: , , , ,

posted by Karthikeyan @ 12:15 AM 2 Comments

Thursday, October 8, 2009

A Great Spark from Microsoft - WebsiteSpark

Microsoft announces WebsiteSpark for Web Portal Owners !!!

With every offer announced by other commercial products, there may be little
* Condition Apply tag appear to declare a Win-Lose chance in which usually customer is the loser. But MS announces a Win-Win chance for website owners to make their portals still in .NET environment.

When more and more open source software users increased, it is Microsoft's turn to bring back the Website Owners and Deployers to Microsoft's Native Platform for their commercial portals and corporate sites.

What a .NET developer would prefer to develop and deploy portals in .NET Technologies, a Website Owner would prefer to use Open Source Database such as MySQL, etc, as it costs nothing.

So, actually what is WebsiteSpark?

Last Month, ScottGu of MS announces the WebsiteSpark program, which holds a couple of free development and production licenses in the .NET Platform for the three years.

The free licenses include:
  • 3 licenses of Visual Studio 2008 Professional Edition
  • 1 license of Expression Studio 3 (which includes Expression Blend, Sketchflow, and Web)
  • 2 licenses of Expression Web 3
  • 4 processor licenses of Windows Web Server 2008 R2
  • 4 processor licenses of SQL Server 2008 Web Edition
  • DotNetPanel control panel (enabling easy remote/hosted management of your servers)
MS believes giving them at no cost encourages the use of .NET deployment environment

What happens after the 3 years?

Still there is no compulsion to continue with the same licenses. But if the user would like to continue, then he has to pay a minimum amount of about Rs.10000/Yr.

For more details:
http://www.microsoft.com/web/websitespark/
http://weblogs.asp.net/scottgu/archive/2009/09/24/announcing-the-websitespark-program.aspx

Labels: ,

posted by Karthikeyan @ 9:51 AM 0 Comments

Wednesday, July 1, 2009

Strange Behavior of NULL Values in SQL Queries

I found a strange behavior of NULL Values when I have a table values as in the following:

Declare @val table
(
Id int,
Username varchar(100),
Desg varchar(100),
Level varchar(100)
)

Insert into @val
select 1,'AAA',NULL,1 union all
select 1,'BBB',NULL,1 union all
select NULL,'CCC','SE',1 union all
select 2,NULL,'PL',4 union all
select 2,'EEE',NULL,5

-- Query 1
select * from @val

-- Query 2
select Id,Username,desg,COUNT(*)
[No. of Employees] from @val
where desg <> 'SE'
group by Id,Username,Desg

-- Query 3
select Id,Username,desg,COUNT(*)
[No. of Employees] from @val
where desg is null or desg <> 'SE'
group by Id,Username,Desg


When we execute the above queries in the Sql Server Management Studio, we would get the following outputs:



Query 1 Result:



Full Table Selection



This is the output of the entire table we just created.



Query 2 Result:



Condition: desg  'SE'



This is the output when I use this condition – desg <> ‘SE’. But it should show the remaining rows that are with NULL values.



Query 3 Result:



Condition: desg IS NULL OR desg  'SE'



when I use this condition – desg IS NULL or desg <> ‘SE’, I am able to get the required output.



Somebody who knows can explain the trick ;-)



Labels: , , , , ,

posted by Karthikeyan @ 10:22 AM 1 Comments

ASP.NET EMail Validation – Revised.

Sometimes back, I had searched to find an easy way to validate email address with some restricted patterns such as fixed domains, common suffices, etc.

The very common regular expression for email validation is as we know:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

But if we want to restrict emails of specific domains, that is also simply possible by :

\w+([-+.']\w+)*@(domA\.com|domB\.com)

The above expression will validate only if the emails are with @domA.com and @domB.com in the suffix.

And When we want to have a specific pattern in the email:


\w+([-+.']\w+)*@(domA+[A-Za-z0-9]*.com)

With the above expression, we can validate email ids with the format abc@domAbbb.com, acde@domAcgfdg32.com, etc. As we could have @domA as the part of the email address after @ symbol.

Labels: , , , , , , ,

posted by Karthikeyan @ 9:28 AM 0 Comments

Saturday, December 20, 2008

Inheritance, Polymorphism and Method Hiding

Whenever I meet .NET people in the code-debate mode, I encounter a common question which is the good example for the concepts like inheritance, polymorphism and method hiding.

Check the code snippet below:
Snippet I:



public class A
{
public virtual methodA()
{
Console.WriteLine("From Class A");
}
}
public class B : A
{
public override methodA()
{
Console.WriteLine("From Class B");
}
}
public class classMain
{
public static void Main(string[] args) {
A objA = new A();
B objB = new B();

// This calls A's methodA()
objA.methodA();


// This calls B's methodA()
objB.methodA();

objA = new B();


// This calls B's methodA()
objA.methodA();
}
}


Consider the change in the Classes B and classMain, as follows:
Snippet II:



public class A
{
public virtual methodA()
{
Console.WriteLine("From Class A");
}
}


public class B : A
{
public new methodA()
{
Console.WriteLine("From Class B");
}
}


public class classMain
{
public static void Main(string[] args)
{
A objA = new A();
B objB = new B();


// This calls A's methodA()
// From the object of class A
objA.methodA();


// This calls B's methodA()
// From the object of class B
objB.methodA();


objA = new B();


// This calls A's methodA()
// From the object of class B
((A)objB).methodA();
}
}


Hope you got the execution flow and output of the above snippets.
I place some questions here:

1) In the snippet I, from the main class, if I want to call the method methodA() of class A by the object of class B, I will get compile time error. Whats the purpose of inheritance here?

2) In the snippet II, from the main class, if I am able to call methodA() of class A by the object of class B, whats the purpose of method overriding then?. (Whenever I see ILDASM, it shows two methodA() in that) .

3) Whats the significant performance improvement in using method overriding over method hiding?

Shoot your answers here...

Labels: , , , , , ,

posted by Karthikeyan @ 6:45 AM 2 Comments