The .NET Knowledge Sharing Thread

Status
Not open for further replies.
Real world tip for n00bs: If you ask for advice, be prepared to follow it before commenting about how it won't work. Experienced programmers take the time out of their day to help you. Try it. If it doesn't work or you don't understand why they suggested the advice or piece of code, please feel free to ask them about it. Some code won't compile because most help will be in the form of pseudo code. It's up to you to interpret this into something workable for yourself.

Remember, programming is not about language. It's about logic. If you understand the logic, you can apply it to any language of programming you desire. If you expect others to give you working code for a problem they couldn't give two ****s about, don't whine about it.
 
Last edited:
What do you expect the output of this program to be?

Code:
using System; 

class Foo
{
    public Foo(string s)
    {
        Console.WriteLine("Foo constructor: {0}", s);
    }
    public void Bar() { }
}

class Base
{
    readonly Foo baseFoo = new Foo("Base initializer");
    public Base()
    {
        Console.WriteLine("Base constructor");
    }
}

class Derived : Base
{
    readonly Foo derivedFoo = new Foo("Derived initializer");
    public Derived()
    {
        Console.WriteLine("Derived constructor");
    }
}

static class Program
{
    static void Main()
    {
        new Derived();
    }
}
 
What do you expect the output of this program to be?

Code:
using System; 

class Foo
{
    public Foo(string s)
    {
        Console.WriteLine("Foo constructor: {0}", s);
    }
    public void Bar() { }
}

class Base
{
    readonly Foo baseFoo = new Foo("Base initializer");
    public Base()
    {
        Console.WriteLine("Base constructor");
    }
}

class Derived : Base
{
    readonly Foo derivedFoo = new Foo("Derived initializer");
    public Derived()
    {
        Console.WriteLine("Derived constructor");
    }
}

static class Program
{
    static void Main()
    {
        new Derived();
    }
}

Shouldn't this rather go in the Programming Quiz thread?
 
Shouldn't this rather go in the Programming Quiz thread?

nope, if you knew the answer you would also know the why* it is so and that is knowledge to share or is it ?

*spoiler warning


well i suppose i should rather just link the tut :D, pleads mini guilty....
 
Last edited:
Lambda, Lambda, Lambda - Uncovering the Mystery Behind Lambda Expressions
Introduction
At first glance, a lambda expression looks like something your professor may have written on the blackboard in calculus class, but in reality, it is "syntactic sugar" built into the C# language over delegates. In this article, we will begin to explore the nuances of lambda expressions by seeing how they they relate to delegates and how they can be used to implement a popular mathematical formula, the quadratic equation.
 
A simple code snippet to compile a piece of C# code at runtime into an executable, saved at the specified path. The sample adds the necessary assembly files to compile a Windows Application:
Code:
Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.CompilerParameters compiler_params = new System.CodeDom.Compiler.CompilerParameters();

compiler_params.OutputAssembly = path;
compiler_params.GenerateExecutable = true;
compiler_params.ReferencedAssemblies.Add("System.dll");
compiler_params.ReferencedAssemblies.Add("System.Drawing.dll");
compiler_params.ReferencedAssemblies.Add("System.Windows.Forms.dll");

System.CodeDom.Compiler.CompilerResults results = provider.CompileAssemblyFromSource(compiler_params, source);

After the code is executed, the "results" variable will contain any compiler errors, so you can easily iterate through the errors to see what went wrong.
 
Nice thread. My first contribution, for those ASP.Net developers that want controls AND the jQuery UI...
Dot Net JQuery
DNJ is a .NET framework that provide advanced AJAX WebControls and features :

* JSON-RPC : Call server side .Net functions from Javascript.
* Ajax extender : Ajaxify your existing .Net controls like the ASP.Net UpdatePanel does, but in a more customisable way
* Advanced pure AJAX WebControls : DNJ integrates all jQuery UI widgets in Visual studio toolbox and allow you to customise them in VS designer.

Please visit http://www.codeproject.com/KB/aspnet/dotnetjquery.aspx for quick documentation
 
PHP Developers

ASP.Net for PHP Developers

This tutorial, for PHP developers, will provide you with an introduction to ASP.NET using the C# language. If you've wondered what ASP.NET is about, this tutorial will strive to answer at least some of your questions. Even if you're an ardent open-source fan, ASP.NET contains some techniques and features that are useful to know about. And, as some might say, it's good to know your enemy!
 
Developing Usable .Net Components

When building an application, developers often face the decision of either writing functionality themselves or look to a third party component to get the job done in a timely manner. In the case of the latter, a well-designed component can greatly enhance a developer's productivity. If you write components, you have an obligation to ensure your components are well-designed, easy to deploy, and above all, easy to use.
 
Extension Methods

Interesting stuff guys, I'd like to add to this thread a little bit atleast:
Extension Methods
Gotta love extension methods, even something as simple as:

public static class SqlDataReaderExtentensions
{
public static object GetNullable(this string input)
{ return string.IsNullOrWhiteSpace(input) ? (object)DBNull.Value : input; }
}

Although, just because it's easy to create extension methods doesn't imply that the functionality provided is simplistic as well!

Here's an extension method I use to perform a deep clone:

Generic Deep Cloning

public static T Clone<T>(this T obj)
{
BinaryFormatter bf = new BinaryFormatter();
bf.SurrogateSelector = new DeepCloneSurrogateSelector();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
ms.Position = 0;
return (T)bf.Deserialize(ms);
}

PS. Sorry about the bad indentation, but the html indentation from the the wysiwyg editor is creating unneccesary line spacing which makes it annoying to read the code.

So get going with extension methods if you haven't tried them out yet!

I might post something later regarding Code Snippets for use with Visual Studio, ADIOS!
 
Last edited:
Status
Not open for further replies.
Top
Sign up to the MyBroadband newsletter
X