|
would it not be a good idea to start looking towards .net 3.0 / 3.5 at this point?
Avalon
Indigo
LinQ
+all the benefits that Christian mentioned for .Net 2.0
As Christian said Generics are the huge improvement in .Net 2.0, they should have been there from the start. From an end user perspective though .Net 2 doesn't make much difference.
VS2005 and orcas are the only IDEs that are meant to run on vista if you ever need to debug Vista issues.
Russell
|
|
|
|
|
Hi the following link will help you with some issues of the .net 2.0 version
http://msdn.microsoft.com/msdnmag/issues/04/05/C20/
|
|
|
|
|
Hi,
I am trying to create a notepad with tabs. I have now run into problems and need some help. My problem is that when i want to open a file into a tab, i dont know which textbox to open in? Each tabpage has a rih textbox as a control. I cant figure out how to get the individual texbox control back.
Here is the code i am trying with sofar:
while ((read = content.ReadLine()) != null)
{
foreach (Control contr in newtabpage.Controls)
{
if (contr.GetType() == typeof(RichTextBox))
{
for (int j = 1; j < newtabpage.Controls.Count; j++)
{
if (rTextBox.Name == "rbox2" )
{
rTextBox.Text += read + "\n";
break;
}
}
}
}
rTextBox.Text += read + "\n";
}
tabControl1.SelectedTab.Text = filename;
content.Close();
This is the code i use when a new tab is created:
rTextBox = new RichTextBox();
rTextBox.Dock = DockStyle.Fill;
rTextBox.Name = "rbox" + tabControl1.TabCount.ToString();
newtabpage = new TabPage();
newtabpage.Controls.Add(rTextBox);
String tn = "ntab" + tabControl1.TabCount.ToString();
newtabpage.Name = tn;
tabControl1.TabPages.Add(newtabpage);
newtabpage.Text = tn;
tabControl1.SelectedTab = newtabpage;
I would be glad if anybody could help me with this. Thanks.
|
|
|
|
|
I'd just make a new class that derives from TabPage and has a property on it that exposes the text box:
public class TextBoxTab : TabPage
{
public RichTextBox TheTextBox
{
return this.richTextBox1;
}
}
Then whenever you add tabs to your TabControl, only add TextBoxTabs:
tabControl1.TabPages.Add(new TextBoxTab());
Your application code would look like this:
string text = File.ReadAllText(theFileName);
TextBoxTab selectedTab = tabControl1.SelectedTab as TextBoxTab;
selectedTab.TheTextBox.Text = text;
|
|
|
|
|
I have a function that a function that takes in a string like "1,2,3,4324,3423". I need to return an array of a type that I specifiy using that string so in this case it would return an array of ints or shorts etc like { 1, 2, 3, 4324, 3423 }.
The code I wrote to do this is below ...
<br />
usage: int[] myInts = (int[])CommaSeparatedStringToIEnumerable("1,2,3,4324,3423", typeof(int)); <br />
<br />
public static IEnumerable CommaSeparatedStringToIEnumerable(string str, <br />
Type destinationType)<br />
{<br />
List<string> list = new List<string>(str.Split(','));<br />
list.RemoveAll(delegate(string s) { return s.Trim().Length == 0 ;});<br />
IEnumerable output;<br />
if (destinationType == typeof(int))<br />
output = list.ConvertAll<int>(delegate(string s) { return Convert.ToInt32(s.Trim()); }).ToArray();<br />
else if (destinationType == typeof(short))<br />
output = list.ConvertAll<short>(delegate(string s) { return Convert.ToInt16(s.Trim()); }).ToArray();<br />
else if (destinationType == typeof(byte))<br />
output = list.ConvertAll<byte>(delegate(string s) { return Convert.ToByte(s.Trim()); }).ToArray();<br />
else if (destinationType == typeof(bool))<br />
output = list.ConvertAll<bool>(delegate(string s) { return Convert.ToBoolean(s.Trim()); }).ToArray();<br />
else if (destinationType == typeof(string))<br />
output = list.ConvertAll<string>(delegate(string s) { return s.Trim(); }).ToArray();<br />
else<br />
throw new NotSupportedException("Type not supported.");<br />
return output;<br />
}
I can't help thinking that this could be acheived using a generic function like
public static T[] CommaSeparatedStringToArray(string str)
but I've been round the houses trying to do this. Any ideas, good articles would be appreciated.
Jim
|
|
|
|
|
static T[] CommaSeparatedStringToIEnumerable<T>(string values)<br />
{<br />
List<string> list = new List<string>(values.Split(','));<br />
List<T> ret = new List<T>();<br />
<br />
foreach(string value in list)<br />
ret.Add(ConvertValue<T>(value));<br />
<br />
return ret.ToArray();<br />
}<br />
<br />
static T ConvertValue<T>(object value)<br />
{<br />
Converter<object, T> convert =<br />
new Converter<object, T>(delegate(object val) { return (T)val; });<br />
<br />
switch(typeof(T).ToString())<br />
{<br />
case "System.Int16":<br />
case "System.Int32":<br />
int RetInt;<br />
if(int.TryParse(value.ToString(), out RetInt))<br />
return convert(RetInt);<br />
break;<br />
<br />
case "System.Single":<br />
float RetFloat;<br />
if(float.TryParse(value.ToString(), out RetFloat))<br />
return convert(RetFloat);<br />
break;<br />
<br />
case "System.Double":<br />
double RetDouble;<br />
if(double.TryParse(value.ToString(), out RetDouble))<br />
return convert(RetDouble);<br />
break;<br />
<br />
default:<br />
return convert(value);<br />
}<br />
<br />
return convert(value);<br />
}
only two letters away from being an asset
|
|
|
|
|
Many thanks Mark, that works a treat!!
Jim
|
|
|
|
|
Here's an elegant way to do it with using C# 2's yield iterators, generics, and delegate inference:
public static IEnumerable<T> CommaSeperatedToIEnumerable<T>(string commaSeperatedValues, Converter<string, T> converter)
{
foreach (string value in commaSeperatedValues.Split(','))
{
yield return converter(value);
}
}
Consuming code would look like this:
IEnumerable<int> myInts = CommaSeperatedSTringToIEnumerable<int>("1,2,3,4324,3423", int.Parse);
Powerful, fun, elegant, works on all types of T. Pretty efficient too, since the results will be computed only as you ask for the values in a foreach.
|
|
|
|
|
Thanks Judah that is quite cool. I'm really enjoying learning the new language features in .NET 2.0!
Jim
|
|
|
|
|
Damn, I always forget about the yield keyword, then get reminded, then forget all about it again.
only two letters away from being an asset
|
|
|
|
|
The real trick of the above solution, of course, is the Converter<int, T> delegate; without it, we'd have to resort back to the a bunch of if/elses using hard coded types. That's no fun.
The yield stuff is really nice. LINQ uses it heavily; you can imagine the LINQ 'where' keyword actually uses a function underneath the hood:
public static IEnumerable<T> Where<T>(IEnumerable<T> items, Predicate<T> criteria)
{
foreach(T item in items)
{
if(criteria(item)) yield return item;
}
}
Of course, with current C# 2 syntax, consuming this is a little ugly:
int[] ints = {5, 10, 15, 20};
IEnumerable<int> evenIntegers = Linq.Where(ints, delegate(int i) { return i % 2 == 0; });
C# 3 makes this a little better with lambda expressions:
IEnumerable<int> evenIntegers = Linq.Where(ints, i => i % 2 == 0);
C# 3 improves it further by extension methods: taking static methods like our Where method and making them appear to be instance methods:
IEnumerable<int> evenIntegers = ints.Where(i => i % 2 == 0);
Better, but still a little odd. The "language integrated" part of LINQ adds some new keywords to C# 3:
IEnumerable<int> evenIntegers = from ints where i % 2 == 0 select i;
Pretty cool stuff; builds heavily on C# 2's delegate inference, anonymous methods, and yielding iterators.
And lastly, it's rather laborious to type IEnumerable<int> all over:
var evenIntegers = from ints where i % 2 == 0 select i;
|
|
|
|
|
Hi
the following code use reflection in order to convert string items to value
types using the static function TryParse.
using System;
using System.Collections.Generic;
using System.Reflection;
namespace CMDLineTest
{
class Program
{
static List<t> CommaSeparatedStringToIEnumerable<t>(string s)
{
List<t> values = new List<t>();
Type targetConversionType = typeof(T);
if (targetConversionType.IsValueType)
{
Type targetConversionTypeOutParamType = Type.GetType(targetConversionType.FullName + @"&");
if(targetConversionTypeOutParamType == null)
throw new Exception("");
MethodInfo tryParseMethodInfo = targetConversionType.GetMethod("TryParse", new Type[] { typeof(string), targetConversionTypeOutParamType });
if(tryParseMethodInfo != null)
{
string[] stringsToConvert = s.Split(',');
T item = default(T);
object[] methodParams = new object[2];
foreach (string str in stringsToConvert)
{
methodParams[0] = str;
methodParams[1] = item;
if (((bool)tryParseMethodInfo.Invoke(null, methodParams)) == true)
values.Add((T)methodParams[1]);
}
}
}
return values;
}
static void Main(string[] args)
{
List<int> intList = CommaSeparatedStringToIEnumerable<int>("1,2,3,4,5");
foreach (int item in intList)
Console.WriteLine(item);
}
}
}
|
|
|
|
|
Hi Friends, can anybody suggest what are the good books for learning C#.NET. I am interested in developing WEB SERVICES in C#.NET
I have knowledge in C, C++, VC++
Suggest some good books using which I can master c#.NET
Thanks ....
poojaaa
|
|
|
|
|
Professional C# Web Services: Building .NET Web Services with ASP.NET and .NET Remoting (Paperback) by wrox publication.
by Andrew Krowczyk (Author), Zach Greenvoss (Author), Christian Nagel (Author), Ashish Banerjee (Author), Thiru Thangarathinam (Author), Aravind Corera (Author), Chris Peiris (Author), Brad Maiani (Author).
Regards,
Satips.
|
|
|
|
|
|
|
|
Does any body know how to capture audio an video form webcam and stream it direcly on to tapi Call, with out first storing it on the disk.
CallieClearence
|
|
|
|
|
hi friends..
while creating a new project in .NET 2 we have an options called Windows Apllication,Windows Control Library,class Library etc..well working on my previous project i used class library to create components in my project..
"Windows Control Library" suggests that we are going to create user controls
but we can do that thing also if we can go for class library(by right clicking class library and thn ADD-->New Item-->user Contrls)..thn whats the diff.
|
|
|
|
|
Well, there's none in reality. The only difference being what you get in the initial project, i.e. either an empty class or a barebones control class. They both compile to .DLL format.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi friends,
plz help me
i am a web developer and now i want to write a desktop application.
the dackend is "ms sql 2000" and front end is "Visual C# 2005".,but i didn\t find any control to connect to ms sql 2000
plz help
prince
|
|
|
|
|
You can use SqlConnection object to connect.
|
|
|
|
|
any control to connect.. if u can suggest me any sampple project then it will be great
prince
|
|
|
|
|
There is no control but you could do something like this:
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "...";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "your sql sp Here";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = ...;
SqlDataReader rdr = cmd.ExecuteReader();
You could look for samples here on codeproject.
|
|
|
|
|
If you type your question in to google, you're bound to find a ton of articles on this.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|